Bug#420010: libapache2-mod-auth-mysql: Automatic reconnect on lost MySQL connections

2007-04-19 Thread Johann Glaser
Package: libapache2-mod-auth-mysql
Version: 4.3.9-3
Severity: normal

Debian Etch uses MySQL 5.0.32. When upgrading from 4.1 (which was used by
Debian Sarge) several things have to be considered as mentioned at
  http://dev.mysql.com/doc/refman/5.0/en/upgrading-from-4-1.html

There is stated quite at the bottom (before the user comments):
--- snip ---
The reconnect flag in the MYSQL structure is set to 0 by
mysql_real_connect(). Only those client programs which did not explicitly
set this flag to 0 or 1 after mysql_real_connect() experience a change.
Having automatic reconnection enabled by default was considered too
dangerous (due to the fact that table locks, temporary tables, user
variables, and session variables are lost after reconnection).
--- snip ---

libapache2-mod-auth-mysql doesn't set the "reconnect" flag so it is
definitely affected by the change.

We've experienced many Apache authentication errors due to lost connections
to the MySQL server. The log file (with high Apache log level) says
  [debug] mod_auth_mysql.c(1223): Query maybe-failed: MySQL server has gone 
away (2006), lastchance=1

Please set the reconnect flag to 1 before mysql_real_connect() which will
hopefully resolve the problem.

-- System Information:
Debian Release: 4.0
  APT prefers stable
  APT policy: (700, 'stable')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.16
Locale: LANG=en_US, LC_CTYPE=en_US (charmap=ISO-8859-1)

Versions of packages libapache2-mod-auth-mysql depends on:
ii  apache2.2-common   2.2.3-4   Next generation, scalable, extenda
ii  libc6  2.3.6.ds1-13  GNU C Library: Shared libraries
ii  libmysqlclient15off5.0.32-7etch1 mysql database client library

libapache2-mod-auth-mysql recommends no packages.

-- no debconf information


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]



Bug#420010: Patch

2007-05-09 Thread Johann Glaser
Hi!

I've resolved the problem by modifying the sources. Please find attached
the patch.

The modified version is now running for more than two weeks and the
reported problem has not reappeared.

Bye
  Hansi

--- libapache-mod-auth-mysql-4.3.9/mod_auth_mysql.c.ori	2007-04-20 10:29:27.0 +0200
+++ libapache-mod-auth-mysql-4.3.9/mod_auth_mysql.c	2007-04-20 10:42:13.0 +0200
@@ -1093,6 +1093,7 @@
 	char *dbname = auth_db_name, *user = auth_db_user, *pwd = auth_db_pwd;
 	void (*sigpipe_handler)();
 	unsigned long client_flag = 0;
+	my_bool do_reconnect = 1;
 
 	APACHELOG(APLOG_DEBUG, r, "Opening DB connection for %s", sec->dir);
 	
@@ -1161,6 +1162,10 @@
 		return errno;
 	}
 
+	/* The default is no longer to automatically reconnect on failure,
+	 * (as of 5.0.3) so we have to set that option here. */
+	mysql_options(sec->dbh, MYSQL_OPT_RECONNECT, &do_reconnect);
+
 	signal(SIGPIPE, sigpipe_handler);
 	
 	APACHELOG(APLOG_DEBUG, r, "Persistent in %s is %i", sec->dir, sec->persistent);