- // 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
- // the DB positions in all datacenters to be safe. If this output is not a redirect,
- // then OutputPage::output() will be relatively slow, meaning that running it in
- // $postCommitWork should help mask the latency of those updates.
- $flags = $lbFactory::SHUTDOWN_CHRONPROT_SYNC;
- $strategy = 'cookie+sync';
-
- $allowHeaders = !( $output->isDisabled() || headers_sent() );
- if ( $output->getRedirect() && $lbFactory->hasOrMadeRecentMasterChanges( INF ) ) {
- // OutputPage::output() will be fast, so $postCommitWork is useless for masking
- // the latency of synchronously updating the DB positions in all datacenters.
- // Try to make use of the time the client spends following redirects instead.
- $domainDistance = self::getUrlDomainDistance( $output->getRedirect() );
- if ( $domainDistance === 'local' && $allowHeaders ) {
- $flags = $lbFactory::SHUTDOWN_CHRONPROT_ASYNC;
- $strategy = 'cookie'; // use same-domain cookie and keep the URL uncluttered
- } elseif ( $domainDistance === 'remote' ) {
- $flags = $lbFactory::SHUTDOWN_CHRONPROT_ASYNC;
- $strategy = 'cookie+url'; // cross-domain cookie might not work
- }
- }
-
+ // Persist the session to avoid race conditions on subsequent requests by the client
+ $request->getSession()->save(); // T214471
+ wfDebug( __METHOD__ . ': session changes committed' );
+
+ // Figure out whether to wait for DB replication now or to use some method that assures
+ // that subsequent requests by the client will use the DB replication positions written
+ // during the shutdown() call below; the later requires working around replication lag
+ // of the store containing DB replication positions (e.g. dynomite, mcrouter).
+ list( $flags, $strategy ) = self::getChronProtStrategy( $lbFactory, $output );