jenkins-bot has submitted this change and it was merged.

Change subject: Avoid self-deadlocks in MessageCache::replace()
......................................................................


Avoid self-deadlocks in MessageCache::replace()

* This makes use of the $rclass flag in BagOStuff

Bug: T109183
Change-Id: I305f51e744aac53876e5865f860c282aa2efbd8b
---
M includes/cache/MessageCache.php
1 file changed, 16 insertions(+), 3 deletions(-)

Approvals:
  Ori.livneh: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/cache/MessageCache.php b/includes/cache/MessageCache.php
index f11a648..9aac37a 100644
--- a/includes/cache/MessageCache.php
+++ b/includes/cache/MessageCache.php
@@ -346,7 +346,7 @@
                                                # Wait for the other thread to 
finish, then retry. Normally,
                                                # the memcached get() will then 
yeild the other thread's result.
                                                $where[] = 'waited for other 
thread to complete';
-                                               $this->mMemc->getScopedLock( 
$cacheKey, self::WAIT_SEC, self::LOCK_TTL );
+                                               $this->getReentrantScopedLock( 
$cacheKey );
                                        }
                                }
                        }
@@ -400,7 +400,7 @@
                # If this lock fails, it doesn't really matter, it just means 
the
                # write is potentially non-atomic, e.g. the results of a 
replace()
                # may be discarded.
-               $mainUnlocker = $memCache->getScopedLock( $cacheKey, 
self::WAIT_SEC, self::LOCK_TTL );
+               $mainUnlocker = $this->getReentrantScopedLock( $cacheKey );
                if ( !$mainUnlocker ) {
                        $where[] = 'could not acquire main lock';
                }
@@ -548,8 +548,13 @@
                        return;
                }
 
+               # Note that if the cache is volatile, load() may trigger a DB 
fetch.
+               # In that case we reenter/reuse the existing cache key lock to 
avoid
+               # a self-deadlock. This is safe as no reads happen *directly* 
in this
+               # method between getReentrantScopedLock() and load() below. 
There is
+               # no risk of data "changing under our feet" for replace().
                $cacheKey = wfMemcKey( 'messages', $code );
-               $scopedLock = $this->mMemc->getScopedLock( $cacheKey, 
self::WAIT_SEC, self::LOCK_TTL );
+               $scopedLock = $this->getReentrantScopedLock( $cacheKey );
                $this->load( $code, self::FOR_UPDATE );
 
                $titleKey = wfMemcKey( 'messages', 'individual', $title );
@@ -674,6 +679,14 @@
        }
 
        /**
+        * @param string $key A language message cache key that stores blobs
+        * @return null|ScopedCallback
+        */
+       protected function getReentrantScopedLock( $key ) {
+               return $this->mMemc->getScopedLock( $key, self::WAIT_SEC, 
self::LOCK_TTL, __METHOD__ );
+       }
+
+       /**
         * Get a message from either the content language or the user language.
         *
         * First, assemble a list of languages to attempt getting the message 
from. This

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I305f51e744aac53876e5865f860c282aa2efbd8b
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to