From 8451f26dcca9534134391bfbdd4a0db591b11e2d Mon Sep 17 00:00:00 2001 From: salilg-eng Date: Mon, 24 Aug 2026 05:32:04 +0000 Subject: [PATCH] fix(Storage): ensure StorageClient retryStrategy is applied correctly to all operations --- Storage/src/Connection/Rest.php | 6 ++++-- Storage/tests/Unit/StorageClientTest.php | 26 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Storage/src/Connection/Rest.php b/Storage/src/Connection/Rest.php index 9388839e8bb4..a520eb2184d6 100644 --- a/Storage/src/Connection/Rest.php +++ b/Storage/src/Connection/Rest.php @@ -317,6 +317,8 @@ public function headObject(array $args = []): array 'prettyPrint' => false, ]; + $args['retryStrategy'] ??= $this->retryStrategy; + $args['restRetryFunction'] = $this->restRetryFunction ?? $this->getRestRetryFunction( 'objects', 'get', @@ -324,7 +326,6 @@ public function headObject(array $args = []): array ); $args += array_filter([ - 'retryStrategy' => $this->retryStrategy, 'restDelayFunction' => $this->restDelayFunction, 'restCalcDelayFunction' => $this->restCalcDelayFunction, 'restRetryListener' => $this->restRetryListener, @@ -1023,6 +1024,8 @@ public function send($resource, $method, array $options = [], $whitelisted = fal ]; $retryResource = isset($retryMap[$resource]) ? $retryMap[$resource] : $resource; + $options['retryStrategy'] ??= $this->retryStrategy; + $options['restRetryFunction'] = $this->restRetryFunction ?? $this->getRestRetryFunction( $retryResource, $method, @@ -1030,7 +1033,6 @@ public function send($resource, $method, array $options = [], $whitelisted = fal ); $options += array_filter([ - 'retryStrategy' => $this->retryStrategy, 'restDelayFunction' => $this->restDelayFunction, 'restCalcDelayFunction' => $this->restCalcDelayFunction, 'restRetryListener' => $this->restRetryListener, diff --git a/Storage/tests/Unit/StorageClientTest.php b/Storage/tests/Unit/StorageClientTest.php index 9fc8c7bf6892..019c76feac37 100644 --- a/Storage/tests/Unit/StorageClientTest.php +++ b/Storage/tests/Unit/StorageClientTest.php @@ -645,6 +645,32 @@ public function testAlwaysRetryStrategySuccessful() $this->assertInstanceOf(Bucket::class, $client->createBucket('myBucket')); } + public function testAlwaysRetryStrategyWithNonIdempotentOpSuccessful() + { + $httpHandler = self::getHttpHandlerMock([ + new Response(503), // Service Unavailable + new Response(200, [], ''), // Successful delete + ])[1]; + + $client = new StorageClient([ + 'projectId' => self::PROJECT, + 'retryStrategy' => StorageClient::RETRY_ALWAYS, + // Mock the httpHandler so it doesn't make a real request + 'httpHandler' => $httpHandler, + // Mock the authHttpHandler so it doesn't make a real request + 'authHttpHandler' => function () { + return new Response(200, [], '{"access_token": "abc"}'); + }, + // Mock the delay function so the tests execute faster + 'restDelayFunction' => function () { + }, + ]); + + $bucket = $client->bucket('myBucket'); + $bucket->object('myObject')->delete(); + $this->assertTrue(true); // If no exception was thrown, we succeeded. + } + public function testDelayFunctionsConfiguration() { $httpHandler = self::getHttpHandlerMock([