From 1f154c01fc3d064f1cf4f9c333775d857afb6528 Mon Sep 17 00:00:00 2001 From: Liviu Chircu Date: Mon, 20 Apr 2015 15:07:49 +0300 Subject: [PATCH] db_mysql: properly set TCP-related timeouts According to official documentation, mysql_options() must be used _after_ mysql_init() --- modules/db_mysql/my_con.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/modules/db_mysql/my_con.c b/modules/db_mysql/my_con.c index 6e9e9869a89..18ea4111e66 100644 --- a/modules/db_mysql/my_con.c +++ b/modules/db_mysql/my_con.c @@ -37,6 +37,11 @@ int db_mysql_connect(struct my_con* ptr) mysql_init(ptr->con); ptr->init = 1; + /* set connect, read and write timeout, the value counts three times */ + mysql_options(ptr->con, MYSQL_OPT_CONNECT_TIMEOUT, &db_mysql_timeout_interval); + mysql_options(ptr->con, MYSQL_OPT_READ_TIMEOUT, &db_mysql_timeout_interval); + mysql_options(ptr->con, MYSQL_OPT_WRITE_TIMEOUT, &db_mysql_timeout_interval); + if (ptr->id->port) { LM_DBG("opening connection: mysql://xxxx:xxxx@%s:%d/%s\n", ZSW(ptr->id->host), ptr->id->port, ZSW(ptr->id->database)); @@ -99,14 +104,6 @@ struct my_con* db_mysql_new_connection(const struct db_id* id) goto err; } - /* set connect, read and write timeout, the value counts three times */ - mysql_options(ptr->con, MYSQL_OPT_CONNECT_TIMEOUT, - (const char *)&db_mysql_timeout_interval); - mysql_options(ptr->con, MYSQL_OPT_READ_TIMEOUT, - (const char *)&db_mysql_timeout_interval); - mysql_options(ptr->con, MYSQL_OPT_WRITE_TIMEOUT, - (const char *)&db_mysql_timeout_interval); - ptr->id = (struct db_id*)id; if (db_mysql_connect(ptr)!=0) {