Browse Source

[5354] Correct auto-reconnect induced mysql client lib segfault

src/lib/dhcpsrv/mysql_connection.cc
    MySqlConnection::openDatabase() -
        Turns off auto_reconnect
        Sets wait_timeout to 30 days
Thomas Markwalder 7 years ago
parent
commit
6b278a3f54
1 changed files with 13 additions and 4 deletions
  1. 13 4
      src/lib/dhcpsrv/mysql_connection.cc

+ 13 - 4
src/lib/dhcpsrv/mysql_connection.cc

@@ -160,16 +160,25 @@ MySqlConnection::openDatabase() {
 
     // Set options for the connection:
     //
-    // Automatic reconnection: after a period of inactivity, the client will
-    // disconnect from the database.  This option causes it to automatically
-    // reconnect when another operation is about to be done.
-    my_bool auto_reconnect = MLM_TRUE;
+    // Set options for the connection:
+    // Make sure auto_reconnect is OFF! Enabling it leaves us with an unusable
+    // connection after a reconnect as among other things, it drops all our
+    // pre-compiled statements.
+    my_bool auto_reconnect = MLM_FALSE;
     int result = mysql_options(mysql_, MYSQL_OPT_RECONNECT, &auto_reconnect);
     if (result != 0) {
         isc_throw(DbOpenError, "unable to set auto-reconnect option: " <<
                   mysql_error(mysql_));
     }
 
+    // Make sure we have a large idle time window ... say 30 days...
+    const char *wait_time = "SET SESSION wait_timeout = 30 * 86400";
+    result = mysql_options(mysql_, MYSQL_INIT_COMMAND, wait_time);
+    if (result != 0) {
+        isc_throw(DbOpenError, "unable to set wait_timeout " <<
+                  mysql_error(mysql_));
+    }
+
     // Set SQL mode options for the connection:  SQL mode governs how what
     // constitutes insertable data for a given column, and how to handle
     // invalid data.  We want to ensure we get the strictest behavior and