Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/297284

Change subject: Fixes to LocalFile::lock()
......................................................................

Fixes to LocalFile::lock()

* Use a ScopedCallback that will also fire on unlockAndRollback()
  as well as on DB errors (via MWExceptionHandler::handleException).
  This prevents locks from getting stuck for minutes when deadlocks
  happen, since the LockManager::destruct() method is not reliable.
* Fix broken reference counting which always released locks on the
  first unlock() call, even if there were 2+ lock() calls.

Bug: T132921
Change-Id: I684706957f4d794cb6fe61505b0d26b7893de706
---
M includes/filerepo/file/LocalFile.php
1 file changed, 8 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/84/297284/1

diff --git a/includes/filerepo/file/LocalFile.php 
b/includes/filerepo/file/LocalFile.php
index 066da60..7fc2246 100644
--- a/includes/filerepo/file/LocalFile.php
+++ b/includes/filerepo/file/LocalFile.php
@@ -1932,16 +1932,21 @@
 
                                throw new LocalFileLockError( $status );
                        }
-                       // Release the lock *after* commit to avoid row-level 
contention
-                       $this->locked++;
-                       $dbw->onTransactionIdle( function () use ( $backend, 
$lockPaths, $logger ) {
+                       // Release the lock *after* commit to avoid row-level 
contention.
+                       // Make sure it triggers on rollback() via 
ScopedCallback (T132921).
+                       $unlocker = new ScopedCallback( function () use ( 
$backend, $lockPaths, $logger ) {
                                $status = $backend->unlockFiles( $lockPaths, 
LockManager::LOCK_EX );
                                if ( !$status->isGood() ) {
                                        $logger->error( "Failed to unlock 
'{file}'", [ 'file' => $this->name ] );
                                }
                        } );
+                       $dbw->onTransactionIdle( function () use ( $unlocker ) {
+                               // Keep $unlocker alive till commit or rollback
+                       } );
                }
 
+               $this->locked++;
+
                return $this->lockedOwnTrx;
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/297284
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I684706957f4d794cb6fe61505b0d26b7893de706
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to