Project

General

Profile

Actions

Bug #518

closed

mysqld disconnects and mod doesn't auto-reconnect

Added by Anonymous about 18 years ago. Updated over 16 years ago.

Status:
Fixed
Priority:
Normal
Category:
mod_mysql_vhost
Target version:
ASK QUESTIONS IN Forums:

Description

PROBLEM:

Connected to a local mysqld trough a unix socket, we get this error when mod_mysql_vhost is trying to lookup the hostname:

2006-02-11 15:11:28: (mod_mysql_vhost.c.349) MySQL server has gone away

We have restarted mysqld and can access (and do queries) over the very same socket using php through mod_php/apache.

SOLUTION:

Restarting lighttpd solved the problem.

ACTION:

Add auto-reconnect code to mod_mysql_vhost.c, as mentioned in
this article on mysql.com
I think the problem is due to mysql connection timeout. (8 hrs by default)

-- rasmus at flajm dot se

Actions #1

Updated by Anonymous about 17 years ago

Maybe this could be a solution...

From the MySQL API manual:
"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 to do this right before mysql_real_connect() in mod_mysql_vhost.c (somewhere around row 255, 1.4.13). It seems to works for me.

my_bool reconnect = 1;

mysql_options(s->mysql, MYSQL_OPT_RECONNECT, &reconnect);

Probably there must be some code to recognize which version of the MySQL library that is in use.

-- patrik

Actions #2

Updated by Anonymous almost 17 years ago

Replying to :

I have tested to do this right before mysql_real_connect() in mod_mysql_vhost.c
(somewhere around row 255, 1.4.13). It seems to works for me.

Thanks Patrik, based on your description I created a .diff. Compile tested for now, hopefully works as well as you said:


--- lighttpd-1.4.x/src/mod_mysql_vhost.c.ORIG   2007-05-02 17:50:58.000000000 +0100
+++ lighttpd-1.4.x/src/mod_mysql_vhost.c        2007-05-02 17:52:50.000000000 +0100
@@ -256,2 +256,6 @@ SERVER_FUNC(mod_mysql_vhost_set_defaults

+                       /* http://trac.lighttpd.net/trac/ticket/518 */
+                       my_bool reconnect = 1;
+                       mysql_options(s->mysql, MYSQL_OPT_RECONNECT, &reconnect);
+
                        if (!mysql_real_connect(s->mysql, FOO(hostname), FOO(myuser), FOO(mypass),

-- lists

Actions #3

Updated by Anonymous almost 17 years ago

Hi darix,

the patch works great (we talked in irc). please don't forget to commit it ;)

-- sr

Actions #4

Updated by glen over 16 years ago

  • Status changed from New to Fixed
  • Resolution set to fixed

applied in r1920 and r1919.

Actions

Also available in: Atom