Skip to content

Commit

Permalink
db_mysql: properly set TCP-related timeouts
Browse files Browse the repository at this point in the history
According to official documentation,  mysql_options() must be used _after_
mysql_init()
  • Loading branch information
liviuchircu committed Apr 20, 2015
1 parent 57f331f commit 1f154c0
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions modules/db_mysql/my_con.c
Expand Up @@ -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));
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 1f154c0

Please sign in to comment.