From e3349116cb9be55586778e823bbdc0a8eb67843e Mon Sep 17 00:00:00 2001 From: Kyle Sanderson Date: Wed, 21 Jan 2015 05:58:45 -0800 Subject: [PATCH] Establish a default timeout for MySQL connectivity. --- extensions/mysql/mysql/MyDriver.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/extensions/mysql/mysql/MyDriver.cpp b/extensions/mysql/mysql/MyDriver.cpp index c6941821..9221c6ff 100644 --- a/extensions/mysql/mysql/MyDriver.cpp +++ b/extensions/mysql/mysql/MyDriver.cpp @@ -96,11 +96,16 @@ MYSQL *Connect(const DatabaseInfo *info, char *error, size_t maxlength) MYSQL *mysql = mysql_init(NULL); const char *host = NULL, *socket = NULL; + decltype(info->maxTimeout) timeout = 60; if (info->maxTimeout > 0) { - mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (const char *)&(info->maxTimeout)); + timeout = info->maxTimeout; } + mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (const char *)&timeout); + mysql_options(mysql, MYSQL_OPT_READ_TIMEOUT, (const char *)&timeout); + mysql_options(mysql, MYSQL_OPT_WRITE_TIMEOUT, (const char *)&timeout); + /* Have MySQL automatically reconnect if it times out or loses connection. * This will prevent "MySQL server has gone away" errors after a while. */