From 646fdc978c0122bc4b465fae64ec8f68a62cebe5 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 18 Jun 2015 11:59:12 -0700 Subject: [PATCH] Added pre-emptive session renewal to avoid "random" submission errors * The session will be renewed on access if it will expire in 10 minutes * This avoids a problem both with 532ef78 + PHP <= 5.5 or any PHP >= 5.6 Bug: T102199 Change-Id: I8cad100bc35e86fa95ad144bcad338f3cb5d82a1 --- .../objectcache/ObjectCacheSessionHandler.php | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/includes/objectcache/ObjectCacheSessionHandler.php b/includes/objectcache/ObjectCacheSessionHandler.php index 789f1e3b61..ae3850f85c 100644 --- a/includes/objectcache/ObjectCacheSessionHandler.php +++ b/includes/objectcache/ObjectCacheSessionHandler.php @@ -31,6 +31,8 @@ class ObjectCacheSessionHandler { /** @var array Map of (session ID => SHA-1 of the data) */ protected static $hashCache = array(); + const TTL_REFRESH_WINDOW = 600; // refresh if expiring in 10 minutes + /** * Install a session handler for the current web request */ @@ -157,10 +159,24 @@ class ObjectCacheSessionHandler { } /** - * Shutdown function. See the comment inside ObjectCacheSessionHandler::install - * for rationale. + * Shutdown function. + * See the comment inside ObjectCacheSessionHandler::install for rationale. */ static function handleShutdown() { + global $wgObjectCacheSessionExpiry; + + $now = microtime( true ); + // Session are only written in object stores when $_SESSION changes, + // which also renews the TTL ($wgObjectCacheSessionExpiry). If a user + // is active but not causing session data changes, it may suddenly + // as they view a form, blocking the first submission. + // Make a dummy change every so often to avoid this. + if ( !isset( $_SESSION['wsExpiresUnix'] ) + || ( $now + self::TTL_REFRESH_WINDOW ) > isset( $_SESSION['wsExpiresUnix'] ) + ) { + $_SESSION['wsExpiresUnix'] = $now + $wgObjectCacheSessionExpiry; + } + session_write_close(); } } -- 2.20.1