Browse Source

Force disconnection in Predis\Pipeline\StandardExecutor when a Predis\ServerException is thrown to prevent protocol desynchronization between the client and the server.

Daniele Alessandri 15 years ago
parent
commit
4c8ecc02e5
1 changed files with 13 additions and 6 deletions
  1. 13 6
      lib/Predis.php

+ 13 - 6
lib/Predis.php

@@ -1541,12 +1541,19 @@ class StandardExecutor implements IPipelineExecutor {
         foreach ($commands as $command) {
             $connection->writeCommand($command);
         }
-        for ($i = 0; $i < $sizeofPipe; $i++) {
-            $response = $connection->readResponse($commands[$i]);
-            $values[] = $response instanceof \Iterator
-                ? iterator_to_array($response)
-                : $response;
-            unset($commands[$i]);
+        try {
+            for ($i = 0; $i < $sizeofPipe; $i++) {
+                $response = $connection->readResponse($commands[$i]);
+                $values[] = $response instanceof \Iterator
+                    ? iterator_to_array($response)
+                    : $response;
+                unset($commands[$i]);
+            }
+        }
+        catch (\Predis\ServerException $exception) {
+            // force disconnection to prevent protocol desynchronization
+            $connection->disconnect();
+            throw $exception;
         }
 
         return $values;