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

Change subject: Reduce chance for parser cache race conditions
......................................................................


Reduce chance for parser cache race conditions

* Move cache time definition to happen before parse so it is less likely
  to override the cache with a stale value and a high cache timestamp.

bug: 46014
Change-Id: I021d27885ac260d89232ff11ec3cccf976e44f0f
---
M includes/WikiPage.php
M includes/parser/ParserCache.php
2 files changed, 12 insertions(+), 8 deletions(-)

Approvals:
  Chad: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/WikiPage.php b/includes/WikiPage.php
index bfa9956..8ea8e35 100644
--- a/includes/WikiPage.php
+++ b/includes/WikiPage.php
@@ -3510,6 +3510,9 @@
                        return false;
                }
 
+               // Reduce effects of race conditions for slow parses (bug 46014)
+               $cacheTime = wfTimestampNow();
+
                $time = - microtime( true );
                $this->parserOutput = $content->getParserOutput( 
$this->page->getTitle(), $this->revid, $this->parserOptions );
                $time += microtime( true );
@@ -3521,7 +3524,8 @@
                }
 
                if ( $this->cacheable && $this->parserOutput->isCacheable() ) {
-                       ParserCache::singleton()->save( $this->parserOutput, 
$this->page, $this->parserOptions );
+                       ParserCache::singleton()->save(
+                               $this->parserOutput, $this->page, 
$this->parserOptions, $cacheTime );
                }
 
                // Make sure file cache is not used on uncacheable content.
diff --git a/includes/parser/ParserCache.php b/includes/parser/ParserCache.php
index 7c5eeb4..7053f13 100644
--- a/includes/parser/ParserCache.php
+++ b/includes/parser/ParserCache.php
@@ -223,19 +223,19 @@
         * @param $parserOutput ParserOutput
         * @param $article Article
         * @param $popts ParserOptions
+        * @param $cacheTime Time when the cache was generated
         */
-       public function save( $parserOutput, $article, $popts ) {
+       public function save( $parserOutput, $article, $popts, $cacheTime = 
null ) {
                $expire = $parserOutput->getCacheExpiry();
-
                if ( $expire > 0 ) {
-                       $now = wfTimestampNow();
+                       $cacheTime = $cacheTime ?: wfTimestampNow();
 
                        $optionsKey = new CacheTime;
                        $optionsKey->mUsedOptions = 
$parserOutput->getUsedOptions();
                        $optionsKey->updateCacheExpiry( $expire );
 
-                       $optionsKey->setCacheTime( $now );
-                       $parserOutput->setCacheTime( $now );
+                       $optionsKey->setCacheTime( $cacheTime );
+                       $parserOutput->setCacheTime( $cacheTime );
 
                        $optionsKey->setContainsOldMagic( 
$parserOutput->containsOldMagic() );
 
@@ -245,8 +245,8 @@
                        // Save the timestamp so that we don't have to load the 
revision row on view
                        $parserOutput->setTimestamp( $article->getTimestamp() );
 
-                       $parserOutput->mText .= "\n<!-- Saved in parser cache 
with key $parserOutputKey and timestamp $now -->\n";
-                       wfDebug( "Saved in parser cache with key 
$parserOutputKey and timestamp $now\n" );
+                       $parserOutput->mText .= "\n<!-- Saved in parser cache 
with key $parserOutputKey and timestamp $cacheTime\n -->\n";
+                       wfDebug( "Saved in parser cache with key 
$parserOutputKey and timestamp $cacheTime\n" );
 
                        // Save the parser output
                        $this->mMemc->set( $parserOutputKey, $parserOutput, 
$expire );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I021d27885ac260d89232ff11ec3cccf976e44f0f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Chad <ch...@wikimedia.org>
Gerrit-Reviewer: Cscott <canan...@wikimedia.org>
Gerrit-Reviewer: Daniel Friesen <dan...@nadir-seen-fire.com>
Gerrit-Reviewer: GWicke <gwi...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to