Merge "rdbms: Use more narrow type hints in LBFactoryTest"
[lhc/web/wiklou.git] / includes / MediaWiki.php
index 00caca9..43512e1 100644 (file)
@@ -569,8 +569,11 @@ class MediaWiki {
        }
 
        /**
-        * This function commits all DB changes as needed before
-        * the user can receive a response (in case commit fails)
+        * This function commits all DB and session changes as needed *before* the
+        * client can receive a response (in case DB commit fails) and thus also before
+        * the response can trigger a subsequent related request by the client
+        *
+        * If there is a significant amount of content to flush, it can be done in $postCommitWork
         *
         * @param IContextSource $context
         * @param callable|null $postCommitWork [default: null]
@@ -598,6 +601,8 @@ class MediaWiki {
                // Run updates that need to block the user or affect output (this is the last chance)
                DeferredUpdates::doUpdates( 'enqueue', DeferredUpdates::PRESEND );
                wfDebug( __METHOD__ . ': pre-send deferred updates completed' );
+               // T214471: persist the session to avoid race conditions on subsequent requests
+               $request->getSession()->save();
 
                // Should the client return, their request should observe the new ChronologyProtector
                // DB positions. This request might be on a foreign wiki domain, so synchronously update
@@ -684,9 +689,10 @@ class MediaWiki {
         */
        private static function getUrlDomainDistance( $url ) {
                $clusterWiki = WikiMap::getWikiFromUrl( $url );
-               if ( $clusterWiki === wfWikiID() ) {
+               if ( WikiMap::isCurrentWikiId( $clusterWiki ) ) {
                        return 'local'; // the current wiki
-               } elseif ( $clusterWiki !== false ) {
+               }
+               if ( $clusterWiki !== false ) {
                        return 'remote'; // another wiki in this cluster/farm
                }
 
@@ -892,17 +898,13 @@ class MediaWiki {
 
                // Loosen DB query expectations since the HTTP client is unblocked
                $trxProfiler = Profiler::instance()->getTransactionProfiler();
-               $trxProfiler->resetExpectations();
-               $trxProfiler->setExpectations(
+               $trxProfiler->redefineExpectations(
                        $this->context->getRequest()->hasSafeMethod()
                                ? $this->config->get( 'TrxProfilerLimits' )['PostSend-GET']
                                : $this->config->get( 'TrxProfilerLimits' )['PostSend-POST'],
                        __METHOD__
                );
 
-               // Important: this must be the last deferred update added (T100085, T154425)
-               DeferredUpdates::addCallableUpdate( [ JobQueueGroup::class, 'pushLazyJobs' ] );
-
                // Do any deferred jobs; preferring to run them now if a client will not wait on them
                DeferredUpdates::doUpdates( $blocksHttpClient ? 'enqueue' : 'run' );