From: Aaron Schulz Date: Tue, 13 May 2014 21:34:23 +0000 (-0700) Subject: Cleaned up database reconnection logic X-Git-Tag: 1.31.0-rc.0~15570^2 X-Git-Url: http://git.cyclocoop.org/data/%24self?a=commitdiff_plain;h=1cf145033057c1a7e70c9957fb354c927c86f350;p=lhc%2Fweb%2Fwiklou.git Cleaned up database reconnection logic * If callbacks are pending, just throw the normal query error exception for the failed query and clear the callbacks. This way an error is still reported, but the handle can be reused if desired, instead of being left broken. Also the reported error makes more sense. bug: 65263 Change-Id: Icb2d372e65e6c62b5d5b90a442ea7b7a7f853adc --- diff --git a/includes/db/Database.php b/includes/db/Database.php index f7fe980c95..dd89c443c7 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -1104,20 +1104,25 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { # Transaction is gone, like it or not $hadTrx = $this->mTrxLevel; // possible lost transaction $this->mTrxLevel = 0; + $this->mTrxIdleCallbacks = array(); // bug 65263 + $this->mTrxPreCommitCallbacks = array(); // bug 65263 wfDebug( "Connection lost, reconnecting...\n" ); if ( $this->ping() ) { + global $wgRequestTime; wfDebug( "Reconnected\n" ); $sqlx = substr( $commentedSql, 0, 500 ); $sqlx = strtr( $sqlx, "\t\n", ' ' ); - global $wgRequestTime; $elapsed = round( microtime( true ) - $wgRequestTime, 3 ); if ( $elapsed < 300 ) { # Not a database error to lose a transaction after a minute or two wfLogDBError( "Connection lost and reconnected after {$elapsed}s, query: $sqlx" ); } - if ( !$hadTrx ) { - # Should be safe to silently retry + if ( $hadTrx ) { + # Leave $ret as false and let an error be reported. + # Callers may catch the exception and continue to use the DB. + } else { + # Should be safe to silently retry (no trx and thus no callbacks) $ret = $this->doQuery( $commentedSql ); } } else {