<p>Ok, so I tested your code in a production system and just replacing the module didn't always seem to do the trick, I still ended up with messages like these:</p>

<pre><code>Nov 25 15:35:26 /usr/sbin/kamailio[15053]: ERROR: db_mysql [km_dbase.c:128]: db_mysql_submit_query(): driver error on query: SSL connection error: socket layer receive error (2026)
Nov 25 15:35:26 /usr/sbin/kamailio[15053]: ERROR: <core> [db_query.c:235]: db_do_insert_cmd(): error while submitting query
</code></pre>

<p>The error above lead me to the conclusion that "mysql_ping()" wasn't performed on these requests. Dug into the MySQL C API and from what I understand the MYSQL_OPT_RECONNECT=true is only used by and acted upon by mysql_ping(), no query functions. So I decreased the "ping_interval" setting to:</p>

<pre><code>modparam("db_mysql", "ping_interval", 5);
</code></pre>

<p>to force mysql_ping to run more frequently. This code has now been running for almost 24h on a production system and it looks promising. Made a small addition to your code to get a warning if connection ID changed after mysql_ping (see attached diff). Now I'm getting a few of these messages:</p>

<pre><code>Nov 26 08:55:27 /usr/sbin/kamailio[29363]: WARNING: db_mysql [km_dbase.c:91]: db_mysql_submit_query(): mysql thread id changed due to reconnect in mysql_ping
</code></pre>

<p>but from what I can see no more failed INSERTs.</p>

<p>I'm thinking MYSQL_OPT_RECONNECT together with frequent mysql_ping()'s seems to have done the trick.</p>

<p><a href="https://github.com/kamailio/kamailio/files/44746/mysql_ping.diff.txt">mysql_ping.diff.txt</a></p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br>Reply to this email directly or <a href="https://github.com/kamailio/kamailio/issues/406#issuecomment-159849980">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AF36ZZHV102lvfKPLNU6OXYdLh5gYylGks5pJr8EgaJpZM4Gmb_R.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/kamailio/kamailio/issues/406#issuecomment-159849980"></link>
  <meta itemprop="name" content="View Issue"></meta>
</div>
<meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>