Merge "objectcache: avoid using heavily time-drifted microtime() values in WAN cache"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 19 Oct 2018 20:55:47 +0000 (20:55 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 19 Oct 2018 20:55:47 +0000 (20:55 +0000)
includes/libs/objectcache/WANObjectCache.php

index 3af820b..e7586cf 100644 (file)
@@ -2225,7 +2225,17 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
         * @codeCoverageIgnore
         */
        protected function getCurrentTime() {
-               return $this->wallClockOverride ?: microtime( true );
+               if ( $this->wallClockOverride ) {
+                       return $this->wallClockOverride;
+               }
+
+               $clockTime = (float)time(); // call this first
+               // microtime() uses an initial gettimeofday() call added to usage clocks.
+               // This can severely drift from time() and the microtime() value of other threads
+               // due to undercounting of the amount of time elapsed. Instead of seeing the current
+               // time as being in the past, use the value of time(). This avoids setting cache values
+               // that will immediately be seen as expired and possibly cause stampedes.
+               return max( microtime( true ), $clockTime );
        }
 
        /**