From cf9fd55578947ee18c14098aa7c42c507546804d Mon Sep 17 00:00:00 2001 From: Thiyagu K Date: Mon, 9 Dec 2024 11:13:36 +0000 Subject: [PATCH] add retry using idempontentOps list add retry using idempontentOps list --- Storage/src/Connection/RetryTrait.php | 1 + Storage/src/SigningHelper.php | 15 +-------------- Storage/tests/Unit/SigningHelperTest.php | 8 +++----- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/Storage/src/Connection/RetryTrait.php b/Storage/src/Connection/RetryTrait.php index 253a10b682d4..67d96a1df754 100644 --- a/Storage/src/Connection/RetryTrait.php +++ b/Storage/src/Connection/RetryTrait.php @@ -69,6 +69,7 @@ trait RetryTrait 'objects.get', 'objects.list', 'serviceaccount.get', + 'signBlob.execute' ]; /** diff --git a/Storage/src/SigningHelper.php b/Storage/src/SigningHelper.php index 592dae8e7a10..110b139f2633 100644 --- a/Storage/src/SigningHelper.php +++ b/Storage/src/SigningHelper.php @@ -25,8 +25,6 @@ use Google\Cloud\Storage\Connection\ConnectionInterface; use Google\Cloud\Core\Exception\ServiceException; use Google\Cloud\Storage\Connection\RetryTrait; -use Google\Cloud\Storage\StorageClient; -use Ramsey\Uuid\Uuid; /** * Provides common methods for signing storage URLs. @@ -909,21 +907,10 @@ private function buildQueryString(array $input) */ private function retrySignBlob(callable $signBlobFn, string $resourceName = 'signBlob', array $args = []) { - $attempts = 0; - $maxRetries = 5; - $invocationId = Uuid::uuid4()->toString(); - $args['retryStrategy'] = StorageClient::RETRY_ALWAYS; - // Generate a retry decider function using the RetryTrait logic. $retryDecider = $this->getRestRetryFunction($resourceName, 'execute', $args); - - while ($attempts < $maxRetries) { - $attempts++; + while (true) { try { - // Attach retry headers - $headers = self::getRetryHeaders($invocationId, $attempts); - $args['headers'] = array_merge($args['headers'] ?? [], $headers); - // Attempt the operation return $signBlobFn(); } catch (\Exception $exception) { diff --git a/Storage/tests/Unit/SigningHelperTest.php b/Storage/tests/Unit/SigningHelperTest.php index b7b50e854dca..5b757e92545e 100644 --- a/Storage/tests/Unit/SigningHelperTest.php +++ b/Storage/tests/Unit/SigningHelperTest.php @@ -806,10 +806,9 @@ public function testRetrySignBlobSuccessFirstAttempt() public function testRetrySignBlobSuccessAfterRetries() { - $attempts = 0; - $signBlobFn = function () use (&$attempts) { - $attempts++; - if ($attempts < 5) { + $attempt = 0; + $signBlobFn = function () use (&$attempt) { + if (++$attempt < 3) { throw new ServiceException('Transient error', 503); } return 'signature'; @@ -820,7 +819,6 @@ public function testRetrySignBlobSuccessAfterRetries() ]); $this->assertEquals('signature', $res); - $this->assertEquals(5, $attempts); } public function testRetrySignBlobNonRetryableError()