X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fclientpool%2FRedisConnectionPool.php;h=dc95727d5665ae61a26b693d7f671ccd3b0d31a3;hb=a0d5ad07d02b6d1cff830b9280ae9dd03f505e04;hp=36d2731cbe22a4f36b9b62e01658ec1a8cfa0b24;hpb=27f8aa732e55f0655255152fa22655fa07424c2d;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/clientpool/RedisConnectionPool.php b/includes/clientpool/RedisConnectionPool.php index 36d2731cbe..dc95727d56 100644 --- a/includes/clientpool/RedisConnectionPool.php +++ b/includes/clientpool/RedisConnectionPool.php @@ -101,7 +101,7 @@ class RedisConnectionPool { $options['connectTimeout'] = 1; } if ( !isset( $options['readTimeout'] ) ) { - $options['readTimeout'] = 31; // handles up to 30 second blocking commands + $options['readTimeout'] = 1; } if ( !isset( $options['persistent'] ) ) { $options['persistent'] = false; @@ -120,7 +120,7 @@ class RedisConnectionPool { * Optional, default is 1 second. * - readTimeout : The timeout for operation reads, in seconds. * Commands like BLPOP can fail if told to wait longer than this. - * Optional, default is 60 seconds. + * Optional, default is 1 second. * - persistent : Set this to true to allow connections to persist across * multiple web requests. False by default. * - password : The authentication password, will be sent to Redis in clear text. @@ -342,6 +342,16 @@ class RedisConnectionPool { return true; } + /** + * Adjust or reset the connection handle read timeout value + * + * @param Redis $conn + * @param int $timeout Optional + */ + public function resetTimeout( Redis $conn, $timeout = null ) { + $conn->setOption( Redis::OPT_READ_TIMEOUT, $timeout ?: $this->readTimeout ); + } + /** * Make sure connections are closed for sanity */ @@ -401,17 +411,34 @@ class RedisConnRef { public function __call( $name, $arguments ) { $conn = $this->conn; // convenience + // Work around https://github.com/nicolasff/phpredis/issues/70 + $lname = strtolower( $name ); + if ( ( $lname === 'blpop' || $lname == 'brpop' ) + && is_array( $arguments[0] ) && isset( $arguments[1] ) + ) { + $this->pool->resetTimeout( $conn, $arguments[1] + 1 ); + } elseif ( $lname === 'brpoplpush' && isset( $arguments[2] ) ) { + $this->pool->resetTimeout( $conn, $arguments[2] + 1 ); + } + $conn->clearLastError(); - $res = call_user_func_array( array( $conn, $name ), $arguments ); - if ( preg_match( '/^ERR operation not permitted\b/', $conn->getLastError() ) ) { - $this->pool->reauthenticateConnection( $this->server, $conn ); - $conn->clearLastError(); + try { $res = call_user_func_array( array( $conn, $name ), $arguments ); - wfDebugLog( 'redis', "Used automatic re-authentication for method '$name'." ); + if ( preg_match( '/^ERR operation not permitted\b/', $conn->getLastError() ) ) { + $this->pool->reauthenticateConnection( $this->server, $conn ); + $conn->clearLastError(); + $res = call_user_func_array( array( $conn, $name ), $arguments ); + wfDebugLog( 'redis', "Used automatic re-authentication for method '$name'." ); + } + } catch ( RedisException $e ) { + $this->pool->resetTimeout( $conn ); // restore + throw $e; } $this->lastError = $conn->getLastError() ?: $this->lastError; + $this->pool->resetTimeout( $conn ); // restore + return $res; }