Ignore errors in RedisConnectionPool destructor
authorGergő Tisza <gtisza@wikimedia.org>
Sun, 13 Aug 2017 14:18:18 +0000 (14:18 +0000)
committerGergő Tisza <gtisza@wikimedia.org>
Mon, 14 Aug 2017 14:28:41 +0000 (14:28 +0000)
The destructor can be called on shutdown so any operation which
relies on another object or resource can fail. E.g. running
anything involving Redis (such as >>new Message('').''<<)
from shell.php and then exiting will result in a RedisException
since the PHP engine closes the Redis connection before destroying
the connection pool. Such errors can be safely ignored.

Change-Id: I38474a9dda89c82edbcb878facb4a97740e9189a

includes/libs/redis/RedisConnectionPool.php

index 99c2c3c..509240f 100644 (file)
@@ -396,9 +396,14 @@ class RedisConnectionPool implements LoggerAwareInterface {
        function __destruct() {
                foreach ( $this->connections as $server => &$serverConnections ) {
                        foreach ( $serverConnections as $key => &$connection ) {
-                               /** @var Redis $conn */
-                               $conn = $connection['conn'];
-                               $conn->close();
+                               try {
+                                       /** @var Redis $conn */
+                                       $conn = $connection['conn'];
+                                       $conn->close();
+                               } catch ( RedisException $e ) {
+                                       // The destructor can be called on shutdown when random parts of the system
+                                       // have been destructed already, causing weird errors. Ignore them.
+                               }
                        }
                }
        }