Index: includes/Wiki.php =================================================================== --- includes/Wiki.php (revision 87499) +++ includes/Wiki.php (working copy) @@ -403,8 +403,7 @@ $this->context->output->output(); // Do any deferred jobs wfDoUpdates( 'commit' ); - // Close the session so that jobs don't access the current session - session_write_close(); + $this->doJobs(); wfProfileOut( __METHOD__ ); } @@ -418,6 +417,11 @@ if ( $wgJobRunRate <= 0 || wfReadOnly() ) { return; } + + // Close the session so that jobs don't access the current session + $this->shutdownLBFactory(); + session_write_close(); + if ( $wgJobRunRate < 1 ) { $max = mt_getrandmax(); if ( mt_rand( 0, $max ) > $max * $wgJobRunRate ) { @@ -449,11 +453,20 @@ public function restInPeace() { MessageCache::logMessages(); wfLogProfilingData(); + $this->shutdownLBFactory(); + wfDebug( "Request ended normally\n" ); + } + + /** + * Commit pending master changes, shutdown the current loadbalancer + * factory and destroys the factory instance. + */ + private function shutdownLBFactory() { // Commit and close up! - $factory = wfGetLBFactory(); + $factory = LBFactory::singleton(); $factory->commitMasterChanges(); $factory->shutdown(); - wfDebug( "Request ended normally\n" ); + LBFactory::destroyInstance(); } /**