[Devel] mysql module failed to reconnect after mysql restart
Norman Brandinger
norm at goes.com
Fri Jan 13 23:33:33 CET 2006
I'm using the CVS version of OpenSER.
A quick "ngrep -R mysql_real_connect" showed only a single instance in:
modules/mysql/my_con.c
I added the following line after the mysql_real_connect block:
ptr->con->reconnect=1;
The code compiled and I was able to restart OpenSER (and access the
MySQL database via fifo). Don't know if the double reference is correct
for setting the reconnect flag. Maybe someone else can confirm it.
Regards,
Norm
Raymond Chen wrote:
>Hi all,
>
>I am using openser 1.0.0 and mysql 5.0.16. I browsed through the mysql
>module, there is no reconnection flag set in mysql_real_connect (did I
>missed anything?), only in submit_query function in dbase.c, auto-reconnect
>should happen when fail to execute a query because of mysql connection lost.
>And that part of the code doesn't seem to work for me. I have tried to
>toggle the auto-reconnect to 0 or 1 in db_mod.c but nothing change.
>
>So do I need to insert the reconnection flag for this to work?
>
>Thanks
>
>Ray
>
>-----Original Message-----
>From: devel-bounces at openser.org [mailto:devel-bounces at openser.org] On Behalf
>Of Dan Pascu
>Sent: Friday, January 13, 2006 1:33 PM
>To: devel at openser.org
>Subject: Re: [Devel] mysql module failed to reconnect after mysql restart
>
>On Friday 13 January 2006 21:18, Norman Brandinger wrote:
>
>
>>Hi Daniel / Raymond
>>
>>Note that upon connection, mysql_real_connect() sets the reconnect flag
>>(part of the MYSQL structure) to a value of 1 in versions of the API
>>older than 5.0.3, or 0 in newer versions. A value of 1 for this flag
>>indicates that if a statement cannot be performed because of a lost
>>connection, to try reconnecting to the server before giving up. As of
>>MySQL 5.0.13, you can use the MYSQL_OPT_RECONNECT option to
>>mysql_options() to control reconnection behavior.
>>
>>I have tested the following code (note that only the important pieces
>>are listed below) and my application was able to automatically
>>reconnect to MySQL. The example below uses BOTH the
>>"MYSQL_OPT_RECONNECT" and the "conn->reconnect = 1" forms to set the
>>reconnect flag. As memory serves, "MYSQL_OPT_RECONNECT" didn't work
>>for me.
>>
>>
>
>Even though the documentation says that you should call mysql_options
>before mysql_real_connect, when setting MYSQL_OPT_RECONNECT you MUST do
>so after the connection has been successfully established.
>
>This is true as late as 5.0.16.
>
>anyway setting conn->reconnect = 1 seems much simpler and less tricky.
>with MYSQL_OPT_RECONNECT, you have to actually make sure you have that
>symbol defined, as it was only introduced in 5.0.13 and the code needs to
>work with all versions of the mysql client lib.
>
>
>
More information about the Devel
mailing list