Fix connection cleanup after interrupted pipelines (#1741)

Disconnect interrupted pipeline connections before they can be reused,
discard remaining commands, and reset running state after PHP errors.
Preserve the original failure when connection cleanup also fails.

Clear the cached connection resource when Relay is closed so the next
command reconnects and replays connection initialization. This fixes
client reuse after an interrupted pipeline disconnects the connection.
This commit is contained in:
Till Krüss
2026-10-09 16:57:05 -07:00
committed by GitHub
parent 78c91a5628
commit 307d7e2b6a
5 changed files with 220 additions and 10 deletions
@@ -13,6 +13,7 @@
namespace Predis\Connection;
use PHPUnit\Framework\MockObject\MockObject;
use Predis\Client;
use Predis\ClientException;
use Predis\Command\RawCommand;
use Predis\NotSupportedException;
@@ -455,6 +456,22 @@ class RelayConnectionTest extends PredisTestCase
// ---- INTEGRATION TESTS --------------------------------------------- //
// ******************************************************************** //
/**
* @group connected
*/
public function testClientReconnectsAfterDisconnect(): void
{
$client = new Client($this->getParameters(), ['connections' => 'relay']);
$this->assertEquals('PONG', $client->ping());
$client->disconnect();
$this->assertFalse($client->isConnected());
$this->assertEquals('PONG', $client->ping());
$this->assertTrue($client->isConnected());
$client->disconnect();
}
/**
* @group connected
*/