From: Aaron Schulz Date: Sat, 20 Feb 2016 00:14:58 +0000 (-0800) Subject: Ignore noop DB transactions errors on connection loss X-Git-Tag: 1.31.0-rc.0~7822^2 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=38f0c072799a298929a922b615c2ba1883c6067b;p=lhc%2Fweb%2Fwiklou.git Ignore noop DB transactions errors on connection loss This avoids some needless exceptions for longer running scripts. Bug: T127428 Change-Id: I3098141aa77a4c73cb2a0c784b38b15c712f82a9 --- diff --git a/includes/db/Database.php b/includes/db/Database.php index 351d43845a..02a6ec870b 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -859,8 +859,12 @@ abstract class DatabaseBase implements IDatabase { # Try reconnecting if the connection was lost if ( false === $ret && $this->wasErrorReissuable() ) { - # Transaction is gone, like it or not - $hadTrx = $this->mTrxLevel; // possible lost transaction + # Transaction is gone; this can mean lost writes or REPEATABLE-READ snapshots + $hadTrx = $this->mTrxLevel; + # T127428: for non-write transactions, a disconnect and a COMMIT are similar: + # neither changed data and in both cases any read snapshots are reset anyway. + $isNoopCommit = ( !$this->writesOrCallbacksPending() && $sql === 'COMMIT' ); + # Update state tracking to reflect transaction loss $this->mTrxLevel = 0; $this->mTrxIdleCallbacks = []; // bug 65263 $this->mTrxPreCommitCallbacks = []; // bug 65263 @@ -874,12 +878,12 @@ abstract class DatabaseBase implements IDatabase { $msg = __METHOD__ . ": lost connection to $server; reconnected"; wfDebugLog( 'DBPerformance', "$msg:\n" . wfBacktrace( true ) ); - if ( $hadTrx || $this->mNamedLocksHeld ) { + if ( ( $hadTrx && !$isNoopCommit ) || $this->mNamedLocksHeld ) { # Leave $ret as false and let an error be reported. # Callers may catch the exception and continue to use the DB. $this->reportQueryError( $lastError, $lastErrno, $sql, $fname, $tempIgnore ); } else { - # Should be safe to silently retry (no trx and thus no callbacks) + # Should be safe to silently retry (no trx/callbacks/locks) $startTime = microtime( true ); $ret = $this->doQuery( $commentedSql ); $queryRuntime = microtime( true ) - $startTime;