From 6a9e507dc515c6116e691afc2148642bc5421b34 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Mon, 22 Aug 2016 23:04:36 -0700 Subject: [PATCH] Reduce problems caused by $wgRunJobsAsync * Use getCanonicalURL() to avoid links with the wrong host (e.g. when it is virtual) and to avoid getting redirects. * Also disable this setting when post-send execution is already available, by default. * Bump the socket timeout slightly. Bug: T107290 Bug: T68485 Change-Id: I56c43193fa6583cc0c8209ff59cf20c986a799a3 --- includes/DefaultSettings.php | 6 +++++- includes/MediaWiki.php | 13 +++++++------ includes/specials/SpecialRunJobs.php | 1 - 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index cbf98a31b9..cad1f63409 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -8033,9 +8033,13 @@ $wgJobRunRate = 1; * When $wgJobRunRate > 0, try to run jobs asynchronously, spawning a new process * to handle the job execution, instead of blocking the request until the job * execution finishes. + * * @since 1.23 */ -$wgRunJobsAsync = true; +$wgRunJobsAsync = ( + !function_exists( 'register_postsend_function' ) && + !function_exists( 'fastcgi_finish_request' ) +); /** * Number of rows to update per job diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php index 7dac0ec30b..77ac76ae4c 100644 --- a/includes/MediaWiki.php +++ b/includes/MediaWiki.php @@ -803,10 +803,10 @@ class MediaWiki { */ public function triggerJobs() { $jobRunRate = $this->config->get( 'JobRunRate' ); - if ( $jobRunRate <= 0 || wfReadOnly() ) { - return; - } elseif ( $this->getTitle()->isSpecial( 'RunJobs' ) ) { + if ( $this->getTitle()->isSpecial( 'RunJobs' ) ) { return; // recursion guard + } elseif ( $jobRunRate <= 0 || wfReadOnly() ) { + return; } if ( $jobRunRate < 1 ) { @@ -843,7 +843,7 @@ class MediaWiki { $query, $this->config->get( 'SecretKey' ) ); $errno = $errstr = null; - $info = wfParseUrl( $this->config->get( 'Server' ) ); + $info = wfParseUrl( $this->config->get( 'CanonicalServer' ) ); MediaWiki\suppressWarnings(); $host = $info['host']; $port = 80; @@ -872,7 +872,8 @@ class MediaWiki { return; } - $url = wfAppendQuery( wfScript( 'index' ), $query ); + $special = SpecialPageFactory::getPage( 'RunJobs' ); + $url = $special->getPageTitle()->getCanonicalURL( $query ); $req = ( "POST $url HTTP/1.1\r\n" . "Host: {$info['host']}\r\n" . @@ -883,7 +884,7 @@ class MediaWiki { $runJobsLogger->info( "Running $n job(s) via '$url'" ); // Send a cron API request to be performed in the background. // Give up if this takes too long to send (which should be rare). - stream_set_timeout( $sock, 1 ); + stream_set_timeout( $sock, 2 ); $bytes = fwrite( $sock, $req ); if ( $bytes !== strlen( $req ) ) { $runJobsLogger->error( "Failed to start cron API (socket write error)" ); diff --git a/includes/specials/SpecialRunJobs.php b/includes/specials/SpecialRunJobs.php index ce5533fbf0..e1e2049d16 100644 --- a/includes/specials/SpecialRunJobs.php +++ b/includes/specials/SpecialRunJobs.php @@ -40,7 +40,6 @@ class SpecialRunJobs extends UnlistedSpecialPage { public function execute( $par = '' ) { $this->getOutput()->disable(); - if ( wfReadOnly() ) { // HTTP 423 Locked HttpStatus::header( 423 ); -- 2.20.1