Fixed connection comparison in RedisConnectionPool::handleException().
authorAaron Schulz <aschulz@wikimedia.org>
Sat, 9 Mar 2013 21:34:22 +0000 (13:34 -0800)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 11 Mar 2013 22:57:33 +0000 (22:57 +0000)
* This was comparing a Redis with a RedisConnRef.

Change-Id: I6353736c8ad42a18d90e8474d38398d305950346

includes/clientpool/RedisConnectionPool.php

index 0c91222..8a3a1be 100644 (file)
@@ -255,15 +255,14 @@ class RedisConnectionPool {
         * object and let it be reopened during the next request.
         *
         * @param $server string
-        * @param $conn RedisConnRef
+        * @param $cref RedisConnRef
         * @param $e RedisException
         * @return void
         */
-       public function handleException( $server, RedisConnRef $conn, RedisException $e ) {
-               wfDebugLog( 'redis',
-                       "Redis exception on server $server: " . $e->getMessage() . "\n" );
+       public function handleException( $server, RedisConnRef $cref, RedisException $e ) {
+               wfDebugLog( 'redis', "Redis exception on server $server: " . $e->getMessage() . "\n" );
                foreach ( $this->connections[$server] as $key => $connection ) {
-                       if ( $connection['conn'] === $conn ) {
+                       if ( $cref->isConnIdentical( $connection['conn'] ) ) {
                                $this->idlePoolSize -= $connection['free'] ? 1 : 0;
                                unset( $this->connections[$server][$key] );
                                break;
@@ -281,12 +280,11 @@ class RedisConnectionPool {
 class RedisConnRef {
        /** @var RedisConnectionPool */
        protected $pool;
-
-       protected $server; // string
-
        /** @var Redis */
        protected $conn;
 
+       protected $server; // string
+
        /**
         * @param $pool RedisConnectionPool
         * @param $server string
@@ -302,6 +300,10 @@ class RedisConnRef {
                return call_user_func_array( array( $this->conn, $name ), $arguments );
        }
 
+       public function isConnIdentical( Redis $conn ) {
+               return $this->conn === $conn;
+       }
+
        function __destruct() {
                $this->pool->freeConnection( $this->server, $this->conn );
        }