Snort.org home  
Got Source? About Snort About Sourcefire Snort FAQ
Sourcefire Network Security - the creators of Snort

Snort Forums Archive

Archive Home » Snort Development » Barnyard-MySQL reconnect problems & solution.

Please note that the categories listed below represent an archived version of our forums pages. To view the current version and be able to post and reply to threads, please register and login here to go to the full forums pages.

[ Notice: Full Version of This Topic ]

Barnyard-MySQL reconnect problems & solution.


Posted by cheesman on November 08, 2005 21:22:04

I recently built barnyard against MySQL 5.0.13 and everything seemed hunkey-dory until I noticed it's failures to reconnect after db restarts. This problem also occurred if the connection was inactive for long periods (>32k sec.?).
In these cases barnyard stays in it's mysql_ping()-sleep loop and never reconnects, even when the db is back online. Small print from the MySQL manual v5.0 for mysql_real_connect() includes the following note:-

>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.

That didn't fix it for me but the following did. I found that adding the line mysql->reconnect = 1; just prior to the mysql_ping() loop did the trick ie. with a couple of lines of context

--- op_acid_db.c.ORIG 2005-11-08 17:05:46.000000000 +0000
+++ op_acid_db.c 2005-11-08 18:19:54.000000000 +0000
@@ -1237,4 +1237,5 @@
{
LogMessage("Lost connection to MySQL server. Reconnecting\n");
+ mysql->reconnect = 1;
while(mysql_ping(mysql) != 0)
{