From 6b278a3f54ecf6bd6e2d381047a9eced4bf165f5 Mon Sep 17 00:00:00 2001 From: Thomas Markwalder Date: Wed, 6 Sep 2017 15:57:38 -0400 Subject: [PATCH] [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 --- src/lib/dhcpsrv/mysql_connection.cc | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/lib/dhcpsrv/mysql_connection.cc b/src/lib/dhcpsrv/mysql_connection.cc index 9d6954a6ca..827c46571a 100644 --- a/src/lib/dhcpsrv/mysql_connection.cc +++ b/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 -- 2.47.2