Make sure the lock in JobRunner::commitMasterChanges() releases
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 8 Sep 2016 09:19:32 +0000 (02:19 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Thu, 8 Sep 2016 09:19:32 +0000 (02:19 -0700)
Used a ScopedCallback in case of exception to avoid queue backup

Change-Id: I58a5f152a54ed9a0d5544014788792bd62afbf4a

includes/jobqueue/JobRunner.php

index 7a6b5fc..570d6db 100644 (file)
@@ -537,6 +537,10 @@ class JobRunner implements LoggerAwareInterface {
                        // This will trigger a rollback in the main loop
                        throw new DBError( $dbwSerial, "Timed out waiting on commit queue." );
                }
+               $unlocker = new ScopedCallback( function () use ( $dbwSerial ) {
+                       $dbwSerial->unlock( 'jobrunner-serial-commit', __METHOD__ );
+               } );
+
                // Wait for the replica DBs to catch up
                $pos = $lb->getMasterPos();
                if ( $pos ) {
@@ -545,8 +549,6 @@ class JobRunner implements LoggerAwareInterface {
 
                // Actually commit the DB master changes
                $lbFactory->commitMasterChanges( $fnameTrxOwner );
-
-               // Release the lock
-               $dbwSerial->unlock( 'jobrunner-serial-commit', __METHOD__ );
+               ScopedCallback::consume( $unlocker );
        }
 }