Skip to content

Commit 003b011

Browse files
chore: set legacy max attempts for DynamoDB
1 parent b41cc25 commit 003b011

3 files changed

Lines changed: 42 additions & 4 deletions

File tree

src/DynamoDb/DynamoDbClient.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Aws\Exception\AwsException;
88
use Aws\HandlerList;
99
use Aws\Middleware;
10+
use Aws\Retry\Configuration;
1011
use Aws\Retry\ConfigurationProvider;
1112
use Aws\RetryMiddleware;
1213
use Aws\RetryMiddlewareV2;
@@ -133,8 +134,9 @@
133134
class DynamoDbClient extends AwsClient
134135
{
135136
/** @internal */
136-
const DYNAMODB_MAX_ATTEMPTS = 4;
137-
const DEFAULT_BASE_DELAY_MS = 25;
137+
private const DYNAMODB_MAX_ATTEMPTS = 4;
138+
private const DEFAULT_BASE_DELAY_MS = 25;
139+
public const DEFAULT_LEGACY_MAX_ATTEMPTS = 10;
138140

139141
public static function getArguments(): array
140142
{
@@ -186,10 +188,17 @@ public static function _applyRetryConfig(mixed $value, array &$args, HandlerList
186188
$config = ConfigurationProvider::unwrap($value);
187189

188190
if ($config->getMode() === 'legacy') {
191+
$effectiveMaxAttempts = $config->getMaxAttempts() - 1;
192+
// If the customer provided config is array and not max attempts
193+
// were specified then we set the default of self::DEFAULT_LEGACY_MAX_ATTEMPTS
194+
if (is_array($value) && !isset($value['max_attempts'])) {
195+
$effectiveMaxAttempts = self::DEFAULT_LEGACY_MAX_ATTEMPTS;
196+
}
197+
189198
$list->appendSign(
190199
Middleware::retry(
191200
RetryMiddleware::createDefaultDecider(
192-
$config->getMaxAttempts() - 1,
201+
$effectiveMaxAttempts,
193202
['error_codes' => ['TransactionInProgressException']]
194203
),
195204
function ($retries) {

tests/DynamoDb/DynamoDbClientTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,33 @@ public function testAppliesRetryStatsConfig($settings)
211211
$this->assertGreaterThan(0, $e->getTransferInfo('retries_attempted'));
212212
}
213213
}
214+
215+
public function testSetLegacyMaxRetries()
216+
{
217+
$client = new DynamoDbClient([
218+
'stats' => ['retries' => true],
219+
'version' => 'latest',
220+
'region' => 'us-west-2',
221+
'handler' => function () {
222+
return new RejectedPromise(
223+
new DynamoDbException('a', new Command('b'), [
224+
'connection_error' => true,
225+
])
226+
);
227+
},
228+
'retries' => [
229+
'mode' => 'legacy'
230+
]
231+
]);
232+
try {
233+
$client->listTables();
234+
$this->fail('The operation should have failed');
235+
} catch (DynamoDbException $e) {
236+
$this->assertNotNull($e->getTransferInfo('retries_attempted'));
237+
$this->assertEquals(
238+
DynamoDbClient::DEFAULT_LEGACY_MAX_ATTEMPTS,
239+
$e->getTransferInfo('retries_attempted')
240+
);
241+
}
242+
}
214243
}

tests/RetryMiddlewareV2Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ function (?string $retryAfter = null) use ($command) {
448448
],
449449
],
450450
],
451-
'Long-Polling backoff when token bucket empty' => [
451+
'Long-Polling backoff when after transient error and token bucket empty' => [
452452
'command' => new Command('ReceiveMessage'),
453453
'queue' => [
454454
$awsException500

0 commit comments

Comments
 (0)