[sr-dev] git:3.1: db_mysql: Fixes crash in libmysqlclient after connection reset.

Daniel-Constantin Mierla miconda at gmail.com
Wed Nov 24 22:38:32 CET 2010


Module: sip-router
Branch: 3.1
Commit: e9709a3c6b2c99e9cc3fd528704aea24e0534a55
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=e9709a3c6b2c99e9cc3fd528704aea24e0534a55

Author: Jan Janak <jan at ryngle.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Wed Nov 17 18:26:32 2010 -0500

db_mysql: Fixes crash in libmysqlclient after connection reset.

Sometimes SIP-Router would crash in libmysqlclient after a connection
to the server has been reset. This is caused by mysql_stmt_prepare
which will reset the connection data structure if a connection has been
reset. Subsequent calls to other mysql functions (mysql_stmt_execute)
crash unless the connection has been re-connected. This is documented
as mysql bug #33384.

A workaround is to reset and reconnect the connection explicitly
immediately after mysql_stmt_prepare has failed with
CR_SERVER_GONE_ERROR. This change implements exactly that.

First of all, this patch fixes a minor bug in updating the variable
that keeps track of number of connection resets for each database
connection and pre-pared statement. The variable needs to be
incremented each time a connection is closed. Previously it was
incremented only if a connection was successfully reconnected. If the
reconnect attempt failed than the variable was not incremented. The
function that uploads commands to the server relies on the variable
to detect connection resets and may not have worked properly under
some circumstances (if a connection fails to reconnect).

Function upload_cmd has been modified to close the connection
explicitly if mysql_stmt_prepare fails with CR_SERVER_GONE_ERROR. This
ensures that subsequent calls to mysql_stmt_exec are forced to reconnect
and re-upload commands to the server. This is needed to prevent the
library from crashing.

exec_cmd_safe now checks if a connection has been disconnected and if
so it tries to reconnect it before executing a prepared statement. This
is used to recover from failing mysql_stmt_prepare.
(cherry picked from commit 0e564bcd3616f9dc981bb768003545674c79c2a7)

---

 modules/db_mysql/my_cmd.c |  258 +++++++++++++++++++++++++--------------------
 modules/db_mysql/my_con.c |   18 ++--
 modules/db_mysql/my_con.h |   10 +-
 3 files changed, 158 insertions(+), 128 deletions(-)

Diff:   http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commitdiff;h=e9709a3c6b2c99e9cc3fd528704aea24e0534a55



More information about the sr-dev mailing list