From b4853a7bea0219c312b0c19cbbb9961e1de47732 Mon Sep 17 00:00:00 2001 From: Theodore Tsirpanis Date: Tue, 27 May 2025 01:06:38 +0300 Subject: [PATCH 1/3] Fix sync-over-async on `DynamoDBRetryPolicy`. --- .../Custom/Internal/DynamoDBRetryPolicy.cs | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/sdk/src/Services/DynamoDBv2/Custom/Internal/DynamoDBRetryPolicy.cs b/sdk/src/Services/DynamoDBv2/Custom/Internal/DynamoDBRetryPolicy.cs index ce9270383ab4..b7885bd4fc8f 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/Internal/DynamoDBRetryPolicy.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/Internal/DynamoDBRetryPolicy.cs @@ -1,12 +1,12 @@ -/* +/* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * + * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at - * + * * http://aws.amazon.com/apache2.0 - * + * * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing @@ -14,10 +14,8 @@ */ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - +using System.Threading; +using System.Threading.Tasks; using Amazon.Runtime; using Amazon.Runtime.Internal; @@ -38,12 +36,12 @@ public DynamoDBRetryPolicy(IClientConfig config) : base(config) { ThrottlingErrorCodes.Add("TransactionInProgressException"); - - //When derived from DefaultRetryPolicy, we are in legacy retry + + //When derived from DefaultRetryPolicy, we are in legacy retry //mode. When in legacy retry mode MaxErrorRetry used to be set //to 10 in the DynamoDB and DynamoDBStreams configs. This //can no longer be set in the configs because the retry mode - //may not be known at that point where standard and adaptive + //may not be known at that point where standard and adaptive //retry modes are not to have this default. if(!config.IsMaxErrorRetrySet) { @@ -57,24 +55,32 @@ public DynamoDBRetryPolicy(IClientConfig config) : /// public override void WaitBeforeRetry(IExecutionContext executionContext) { - pauseExponentially(executionContext.RequestContext.Retries); + Thread.Sleep(CalculateRetryDelay(executionContext.RequestContext.Retries)); + } + + /// + /// Overriden to cause a pause between retries. + /// + /// + public override Task WaitBeforeRetryAsync(IExecutionContext executionContext) + { + return Task.Delay(CalculateRetryDelay(executionContext.RequestContext.Retries), executionContext.RequestContext.CancellationToken); } /// /// Override the pausing function so retries would happen more frequent then the default operation. /// - /// Current number of retries. - private void pauseExponentially(int retries) + private int CalculateRetryDelay(int retries) { int delay; - + if (retries <= 0) delay = 0; else if (retries < 20) delay = Convert.ToInt32(Math.Pow(2, retries - 1) * 50.0); else delay = Int32.MaxValue; if (retries > 0 && (delay > MaxBackoffInMilliseconds || delay <= 0)) delay = MaxBackoffInMilliseconds; - Amazon.Util.AWSSDKUtils.Sleep(delay); + return delay; } } } From 70889d863bf11e3882e9e6e74480eeaeef4890ff Mon Sep 17 00:00:00 2001 From: Theodore Tsirpanis Date: Mon, 9 Jun 2025 22:27:46 +0300 Subject: [PATCH 2/3] Switch back to using `AWSSDKUtils.Sleep`. --- .../Services/DynamoDBv2/Custom/Internal/DynamoDBRetryPolicy.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sdk/src/Services/DynamoDBv2/Custom/Internal/DynamoDBRetryPolicy.cs b/sdk/src/Services/DynamoDBv2/Custom/Internal/DynamoDBRetryPolicy.cs index b7885bd4fc8f..a59298271fc2 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/Internal/DynamoDBRetryPolicy.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/Internal/DynamoDBRetryPolicy.cs @@ -14,7 +14,6 @@ */ using System; -using System.Threading; using System.Threading.Tasks; using Amazon.Runtime; using Amazon.Runtime.Internal; @@ -55,7 +54,7 @@ public DynamoDBRetryPolicy(IClientConfig config) : /// public override void WaitBeforeRetry(IExecutionContext executionContext) { - Thread.Sleep(CalculateRetryDelay(executionContext.RequestContext.Retries)); + Amazon.Util.AWSSDKUtils.Sleep(CalculateRetryDelay(executionContext.RequestContext.Retries)); } /// From 1f2f6e7d8fdc77c5d8462f0fe2ae0430f1856318 Mon Sep 17 00:00:00 2001 From: Muhammad Othman Date: Mon, 9 Jun 2025 16:47:58 -0400 Subject: [PATCH 3/3] Add Dev Config --- .../1cecd29e-66f5-4ac7-be16-2df3ba18f3d2.json | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 generator/.DevConfigs/1cecd29e-66f5-4ac7-be16-2df3ba18f3d2.json diff --git a/generator/.DevConfigs/1cecd29e-66f5-4ac7-be16-2df3ba18f3d2.json b/generator/.DevConfigs/1cecd29e-66f5-4ac7-be16-2df3ba18f3d2.json new file mode 100644 index 000000000000..7e794ed2d15f --- /dev/null +++ b/generator/.DevConfigs/1cecd29e-66f5-4ac7-be16-2df3ba18f3d2.json @@ -0,0 +1,11 @@ +{ + "services": [ + { + "serviceName": "DynamoDBv2", + "type": "patch", + "changeLogMessages": [ + "Add DynamoDBRetryPolicy.WaitBeforeRetryAsync override method in order to use the updated retry logic for async retries." + ] + } + ] +} \ No newline at end of file