Aaron Schulz has uploaded a new change for review.

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

Change subject: Moved ObjectCacheSessionHandler renewal logic to 
wfSetupSession()
......................................................................

Moved ObjectCacheSessionHandler renewal logic to wfSetupSession()

* This should trigger more reliably than the shutdown function
  callback, which is really only there for sanity to make sure
  session close/write happens.

Change-Id: I9a1aa76de121ba8de33b3fa850bd223929fae404
---
M includes/GlobalFunctions.php
M includes/objectcache/ObjectCacheSessionHandler.php
2 files changed, 26 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/75/228975/1

diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php
index 167305d..49d3d34 100644
--- a/includes/GlobalFunctions.php
+++ b/includes/GlobalFunctions.php
@@ -3462,8 +3462,9 @@
  * @param bool $sessionId
  */
 function wfSetupSession( $sessionId = false ) {
-       global $wgSessionsInMemcached, $wgSessionsInObjectCache, $wgCookiePath, 
$wgCookieDomain,
-                       $wgCookieSecure, $wgCookieHttpOnly, $wgSessionHandler;
+       global $wgSessionsInMemcached, $wgSessionsInObjectCache, 
$wgSessionHandler;
+       global $wgCookiePath, $wgCookieDomain, $wgCookieSecure, 
$wgCookieHttpOnly;
+
        if ( $wgSessionsInObjectCache || $wgSessionsInMemcached ) {
                ObjectCacheSessionHandler::install();
        } elseif ( $wgSessionHandler && $wgSessionHandler != ini_get( 
'session.save_handler' ) ) {
@@ -3471,6 +3472,7 @@
                # hasn't already been set to the desired value (that causes 
errors)
                ini_set( 'session.save_handler', $wgSessionHandler );
        }
+
        session_set_cookie_params(
                0, $wgCookiePath, $wgCookieDomain, $wgCookieSecure, 
$wgCookieHttpOnly );
        session_cache_limiter( 'private, must-revalidate' );
@@ -3479,9 +3481,14 @@
        } else {
                wfFixSessionID();
        }
+
        MediaWiki\suppressWarnings();
        session_start();
        MediaWiki\restoreWarnings();
+
+       if ( $wgSessionsInObjectCache || $wgSessionsInMemcached ) {
+               ObjectCacheSessionHandler::renewCurrentSession();
+       }
 }
 
 /**
diff --git a/includes/objectcache/ObjectCacheSessionHandler.php 
b/includes/objectcache/ObjectCacheSessionHandler.php
index 1430dd8..ec6fcc3 100644
--- a/includes/objectcache/ObjectCacheSessionHandler.php
+++ b/includes/objectcache/ObjectCacheSessionHandler.php
@@ -21,6 +21,8 @@
  * @ingroup Cache
  */
 
+use MediaWiki\Logger\LoggerFactory;
+
 /**
  * Session storage in object cache.
  * Used if $wgSessionsInObjectCache is true.
@@ -28,9 +30,6 @@
  * @ingroup Cache
  */
 class ObjectCacheSessionHandler {
-
-       const TTL_REFRESH_WINDOW = 600; // refresh if expiring in 10 minutes
-
        /**
         * Install a session handler for the current web request
         */
@@ -145,20 +144,31 @@
         * See the comment inside ObjectCacheSessionHandler::install for 
rationale.
         */
        static function handleShutdown() {
+               session_write_close();
+       }
+
+       /**
+        * Pre-emptive session renewal function
+        */
+       static function renewCurrentSession() {
                global $wgObjectCacheSessionExpiry;
+
+               // Once a session is at half TTL, renew it
+               $window = $wgObjectCacheSessionExpiry / 2;
 
                $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.
+               // expire 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'] )
+                       || ( $now + $window ) > isset( 
$_SESSION['wsExpiresUnix'] )
                ) {
                        $_SESSION['wsExpiresUnix'] = $now + 
$wgObjectCacheSessionExpiry;
-               }
 
-               session_write_close();
+                       $logger = LoggerFactory::getInstance( 'SessionHandler' 
);
+                       $logger->info( "Renewed session " . session_id(), 
array() );
+               }
        }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9a1aa76de121ba8de33b3fa850bd223929fae404
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