title: MariaDB server times out client connection after 600 seconds
body: <p>My MariaDB server is timing out my C++ client (using libmariadb) after 600 seconds (10 minutes) of inactivity, and I'm not sure why, because I can't find any configured timeouts that specify that number.</p>
  <p>Here's my code, where I execute a simple SELECT query, wait 11 minutes, then run that same query again and get a &quot;server gone&quot; error:</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;unistd.h&gt;
  
  #include &lt;errmsg.h&gt;
  #include &lt;mysql.h&gt;
  
  int main(int, char**)
  {
      // connect to the database
      MYSQL* connection = mysql_init(NULL);
      my_bool reconnect = 0;
      mysql_options(connection, MYSQL_OPT_RECONNECT, &amp;reconnect);  // don't implicitly reconnect
      mysql_real_connect(connection, &quot;127.0.0.1&quot;, &quot;testuser&quot;, &quot;password&quot;,
                         &quot;my_test_db&quot;, 3306, NULL, 0);
  
      // run a simple query
      mysql_query(connection, &quot;select 5&quot;);
      mysql_free_result(mysql_store_result(connection));
      std::cout &lt;&lt; &quot;First query done...\n&quot;;
  
      // sleep for 11 minutes
      sleep(660);
  
      // run the query again
      if(! mysql_query(connection, &quot;select 5&quot;))
      {
          std::cout &lt;&lt; &quot;Second query succeeded after &quot; &lt;&lt; seconds &lt;&lt; &quot; seconds\n&quot;;
          mysql_free_result(mysql_store_result(connection));
      }
      else
      {
          if(mysql_errno(connection) == CR_SERVER_GONE_ERROR)
          {
              // **** this happens every time ****
              std::cout &lt;&lt; &quot;Server went away after &quot; &lt;&lt; seconds &lt;&lt; &quot; seconds\n&quot;;
          }
      }
  
      // close the connection
      mysql_close(connection);
      connection = nullptr;
  
      return 0;
  }
  </code></pre>
  <p>The stdout of the server process reports that it timed out my connection:</p>
  <pre><code>$ sudo journalctl -u mariadb
  ...
  Jul 24 17:58:31 myhost mysqld[407]: 2018-07-24 17:58:31 139667452651264 [Warning] Aborted connection 222 to db: 'my_test_db' user: 'testuser' host: 'localhost' (Got timeout reading communication packets)
  ...
  </code></pre>
  <p>Looking at a tcpdump capture, I can also see the server sending the client a TCP FIN packet, which closes the connection.</p>
  <p>The reason I'm stumped is because I haven't changed any of the default timeout values, <em>none</em> of which are even 600 seconds:</p>
  <pre><code>MariaDB [(none)]&gt; show variables like '%timeout%';
  +-------------------------------------+----------+
  | Variable_name                       | Value    |
  +-------------------------------------+----------+
  | connect_timeout                     | 10       |
  | deadlock_timeout_long               | 50000000 |
  | deadlock_timeout_short              | 10000    |
  | delayed_insert_timeout              | 300      |
  | innodb_flush_log_at_timeout         | 1        |
  | innodb_lock_wait_timeout            | 50       |
  | innodb_print_lock_wait_timeout_info | OFF      |
  | innodb_rollback_on_timeout          | OFF      |
  | interactive_timeout                 | 28800    |
  | lock_wait_timeout                   | 31536000 |
  | net_read_timeout                    | 30       |
  | net_write_timeout                   | 60       |
  | slave_net_timeout                   | 3600     |
  | thread_pool_idle_timeout            | 60       |
  | wait_timeout                        | 28800    |
  +-------------------------------------+----------+
  </code></pre>
  <p>So why is the server timing out my connection? Based on the documentation, I would have thought it would have been because of the <code>wait_timeout</code> server variable, but it's left at the default of 8 hours...</p>
  <p>BTW I'm using MariaDB 10.0 and libmariadb 2.0 (from the Ubuntu Xenial Universe repo)</p>
  <hr />
  <p>Edit: here's an image of a tcpdump capture catching the disconnect. My Wireshark filter is <code>tcp.port == 55916</code>, so I'm looking at traffic to/from this one client connection. The FIN packet that the server sends is packet 1199, exactly 600 seconds after the previous packet (884).
  <a href="https://i.stack.imgur.com/xbE01.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xbE01.jpg" alt="pcap opened in wireshark" /></a></p>