From e93496f04d400a0d998865f15a37a9e9f63cd882 Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Thu, 18 Feb 2010 05:28:22 +0000 Subject: [PATCH] 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. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18672 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/backend/dbi/gnc-backend-dbi.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/backend/dbi/gnc-backend-dbi.c b/src/backend/dbi/gnc-backend-dbi.c index 20f155f97b..07cc93af1e 100644 --- a/src/backend/dbi/gnc-backend-dbi.c +++ b/src/backend/dbi/gnc-backend-dbi.c @@ -1377,6 +1377,14 @@ conn_begin_transaction( /*@ unused @*/ GncSqlConnection* conn ) 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" );