From 883a2eeb3e98844ad7b70b9719f2aa8f16c09ee7 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Tue, 24 Sep 2024 10:37:04 -0400 Subject: [PATCH 1/2] Retry once when disabling fail points (#1445) The previous refactor in 90dcf186c8664a2cdd57314122d46b16234555c2 changed when we disable fail points. ManagesFailPointTrait now does so immediately after test operations are run instead of during tear down, so we may be hitting a point where the server stream was disconnected and libmongoc is not recovering (possibly related to CDRIVER-4532). Adding an extra retry attempt seems to overcome this. --- tests/UnifiedSpecTests/ManagesFailPointsTrait.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/UnifiedSpecTests/ManagesFailPointsTrait.php b/tests/UnifiedSpecTests/ManagesFailPointsTrait.php index d88368fa9..1fbe0fd6a 100644 --- a/tests/UnifiedSpecTests/ManagesFailPointsTrait.php +++ b/tests/UnifiedSpecTests/ManagesFailPointsTrait.php @@ -2,6 +2,7 @@ namespace MongoDB\Tests\UnifiedSpecTests; +use MongoDB\Driver\Exception\ConnectionException; use MongoDB\Driver\Server; use MongoDB\Operation\DatabaseCommand; use stdClass; @@ -31,8 +32,14 @@ public function configureFailPoint(stdClass $failPoint, Server $server): void public function disableFailPoints(): void { foreach ($this->failPointsAndServers as [$failPoint, $server]) { - $operation = new DatabaseCommand('admin', ['configureFailPoint' => $failPoint, 'mode' => 'off']); - $operation->execute($server); + try { + $operation = new DatabaseCommand('admin', ['configureFailPoint' => $failPoint, 'mode' => 'off']); + $operation->execute($server); + } catch (ConnectionException $e) { + // Retry once in case the connection was dropped by the last operation + $operation = new DatabaseCommand('admin', ['configureFailPoint' => $failPoint, 'mode' => 'off']); + $operation->execute($server); + } } $this->failPointsAndServers = []; From d1c134460089cdc7f75a76bc99bb1f2c080207c2 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Tue, 24 Sep 2024 16:44:25 +0200 Subject: [PATCH 2/2] Use non-capturing catch statement --- tests/UnifiedSpecTests/ManagesFailPointsTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/UnifiedSpecTests/ManagesFailPointsTrait.php b/tests/UnifiedSpecTests/ManagesFailPointsTrait.php index 1fbe0fd6a..230d53694 100644 --- a/tests/UnifiedSpecTests/ManagesFailPointsTrait.php +++ b/tests/UnifiedSpecTests/ManagesFailPointsTrait.php @@ -35,7 +35,7 @@ public function disableFailPoints(): void try { $operation = new DatabaseCommand('admin', ['configureFailPoint' => $failPoint, 'mode' => 'off']); $operation->execute($server); - } catch (ConnectionException $e) { + } catch (ConnectionException) { // Retry once in case the connection was dropped by the last operation $operation = new DatabaseCommand('admin', ['configureFailPoint' => $failPoint, 'mode' => 'off']); $operation->execute($server);