r18672 - gnucash/trunk/src/backend/dbi - Bug #608032: Handle MySQL connection timeouts with reconnect

Christian Stimming cstim at code.gnucash.org
Thu Feb 18 00:28:23 EST 2010


Author: cstim
Date: 2010-02-18 00:28:22 -0500 (Thu, 18 Feb 2010)
New Revision: 18672
Trac: http://svn.gnucash.org/trac/changeset/18672

Modified:
   gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c
Log:
Bug #608032: Handle MySQL connection timeouts with reconnect

Patch by Tom van Braeckel:

For the full discussion, see the mailing list:
https://lists.gnucash.org/pipermail/gnucash-devel/2010-February/027323.html

Rationale: When we try to open a database transaction, and the database reports
that the "server has gone away", we try to reconnect before failing hard.

Modified: gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c
===================================================================
--- gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c	2010-02-18 05:27:55 UTC (rev 18671)
+++ gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c	2010-02-18 05:28:22 UTC (rev 18672)
@@ -1377,6 +1377,14 @@
 
 	DEBUG( "BEGIN\n" );
 	result = dbi_conn_queryf( dbi_conn->conn, "BEGIN" );
+
+	/* Handle MySQL connection timeouts with reconnect */
+	if (result == NULL && dbi_conn_error( dbi_conn->conn, NULL ) == 2006 ) {
+		DEBUG( "MySQL server has gone away, reconnecting and retrying...\n" );
+		(void)dbi_conn_connect( dbi_conn->conn );
+		result = dbi_conn_queryf( dbi_conn->conn, "BEGIN" );
+	}
+
 	status = dbi_result_free( result );
 	if( status < 0 ) {
 		PERR( "Error in dbi_result_free() result\n" );



More information about the gnucash-changes mailing list