Skip to content

Commit 714da31

Browse files
committed
Make Retry Behavior 2.1 the default retry behavior
1 parent a30491b commit 714da31

27 files changed

Lines changed: 555 additions & 129 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "feature",
3+
"category": "aws-cpp-sdk-core",
4+
"contributor": "pulimsr",
5+
"description": "Make Retry Behavior 2.1 the default retry behavior and remove AWS_NEW_RETRIES_2026. Set AWS_RETRY_MODE=legacy or retry_mode = legacy, or use DefaultRetryStrategy, to keep the previous behavior. Custom retry strategies now also get the Retry Behavior 2.1 request handling."
6+
}

‎generated/src/aws-cpp-sdk-dynamodb/source/DynamoDBClientConfiguration.cpp‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ void DynamoDBClientConfiguration::LoadDynamoDBSpecificConfig(const Aws::String&
3737
if (!enableEndpointDiscovery) {
3838
enableEndpointDiscovery = IsEndpointDiscoveryEnabled(this->endpointOverride, inputProfileName);
3939
}
40-
this->configFactories.retryStrategyCreateFn = []() -> std::shared_ptr<Client::RetryStrategy> {
41-
return Client::InitRetryStrategy(4, "", 0.025);
40+
const Aws::String retryProfileName = this->profileName;
41+
this->configFactories.retryStrategyCreateFn = [retryProfileName]() -> std::shared_ptr<Client::RetryStrategy> {
42+
return Client::InitRetryStrategy(4, "", 0.025, retryProfileName);
4243
};
4344
}
4445

‎generated/src/aws-cpp-sdk-dynamodbstreams/source/DynamoDBStreamsClientConfiguration.cpp‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ namespace Aws {
99
namespace DynamoDBStreams {
1010

1111
void DynamoDBStreamsClientConfiguration::LoadDynamoDBStreamsSpecificConfig(const Aws::String& inputProfileName) {
12-
this->configFactories.retryStrategyCreateFn = []() -> std::shared_ptr<Client::RetryStrategy> {
13-
return Client::InitRetryStrategy(4, "", 0.025);
12+
const Aws::String retryProfileName = this->profileName;
13+
this->configFactories.retryStrategyCreateFn = [retryProfileName]() -> std::shared_ptr<Client::RetryStrategy> {
14+
return Client::InitRetryStrategy(4, "", 0.025, retryProfileName);
1415
};
1516
#if defined(_MSC_VER)
1617
(&reinterpret_cast<const int&>(inputProfileName));

‎src/aws-cpp-sdk-core/include/aws/core/client/AWSProtocolClient.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ namespace Aws
175175

176176
error.SetResponseHeaders(httpResponse->GetHeaders());
177177
error.SetResponseCode(httpResponse->GetResponseCode());
178+
if (error.GetResponseCode() == Aws::Http::HttpResponseCode::TOO_MANY_REQUESTS && error.GetErrorType() == CoreErrors::UNKNOWN)
179+
{
180+
error.SetRetryableType(RetryableType::RETRYABLE_THROTTLING);
181+
}
178182
error.SetRemoteHostIpAddress(httpResponse->GetOriginatingRequest().GetResolvedRemoteHost());
179183
AWS_LOGSTREAM_ERROR(GetClientLogTag(), error);
180184
return error;

‎src/aws-cpp-sdk-core/include/aws/core/client/AdaptiveRetryStrategy.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class AWS_CORE_API AdaptiveRetryStrategy : public StandardRetryStrategy
127127
*/
128128
AdaptiveRetryStrategy(long maxAttempts = 3);
129129
AdaptiveRetryStrategy(std::shared_ptr<RetryQuotaContainer> retryQuotaContainer, long maxAttempts = 3);
130+
AdaptiveRetryStrategy(long maxAttempts, double transientBackoffBaseSec);
130131

131132
/**
132133
* Retrieve and consume a send token.

‎src/aws-cpp-sdk-core/include/aws/core/client/ClientConfiguration.h‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ namespace Aws
109109
struct ProviderFactories
110110
{
111111
/**
112-
* Retry Strategy factory method. Default is DefaultRetryStrategy (i.e. exponential backoff).
112+
* Retry Strategy factory method. Default is StandardRetryStrategy.
113113
*/
114114
std::function<std::shared_ptr<RetryStrategy>()> retryStrategyCreateFn;
115115
/**
@@ -229,7 +229,7 @@ namespace Aws
229229
*/
230230
unsigned long lowSpeedLimit = 1;
231231
/**
232-
* Strategy to use in case of failed requests. Default is DefaultRetryStrategy (i.e. exponential backoff).
232+
* Strategy to use in case of failed requests. Default is StandardRetryStrategy.
233233
* Provide retry strategy here or via a factory method.
234234
*/
235235
std::shared_ptr<RetryStrategy> retryStrategy = nullptr;
@@ -652,11 +652,13 @@ namespace Aws
652652

653653
/**
654654
* A helper function to initialize a retry strategy.
655-
* Default is DefaultRetryStrategy (i.e. exponential backoff)
655+
* Default is StandardRetryStrategy. Retry mode "legacy" uses DefaultRetryStrategy.
656656
*/
657657
AWS_CORE_API std::shared_ptr<RetryStrategy> InitRetryStrategy(Aws::String retryMode = "");
658658
AWS_CORE_API std::shared_ptr<RetryStrategy> InitRetryStrategy(int maxRetries, Aws::String retryMode = "");
659659
AWS_CORE_API std::shared_ptr<RetryStrategy> InitRetryStrategy(int maxRetries, Aws::String retryMode, double transientBackoffBaseSec);
660+
AWS_CORE_API std::shared_ptr<RetryStrategy> InitRetryStrategy(int maxRetries, Aws::String retryMode, double transientBackoffBaseSec,
661+
const Aws::String& profileName);
660662

661663
/**
662664
* A helper function to compute a user agent

‎src/aws-cpp-sdk-core/include/aws/core/internal/RetryStrategyImpl.h‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
#include <aws/core/client/AWSError.h>
1010
#include <aws/core/client/CoreErrors.h>
1111
#include <aws/core/client/RetryStrategy.h>
12+
#include <aws/core/utils/memory/stl/AWSString.h>
1213
#include <aws/core/utils/threading/ReaderWriterLock.h>
1314

15+
#include <memory>
16+
1417
namespace Aws
1518
{
1619
namespace Client
@@ -73,5 +76,19 @@ namespace Aws
7376
mutable Aws::Utils::Threading::ReaderWriterLock m_retryQuotaLock;
7477
int m_retryQuota;
7578
};
79+
80+
namespace Internal
81+
{
82+
AWS_CORE_LOCAL bool UsesRetryBehavior21(const RetryStrategy* retryStrategy);
83+
84+
inline void ClassifyUnmodeledTooManyRequests(AWSError<CoreErrors>& error)
85+
{
86+
if (error.GetResponseCode() == Aws::Http::HttpResponseCode::TOO_MANY_REQUESTS &&
87+
error.GetErrorType() == CoreErrors::UNKNOWN)
88+
{
89+
error.SetRetryableType(RetryableType::RETRYABLE_THROTTLING);
90+
}
91+
}
92+
} // namespace Internal
7693
} // namespace Client
7794
} // namespace Aws

‎src/aws-cpp-sdk-core/include/smithy/client/AwsSmithyClientBase.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ namespace client
115115
Aws::MakeShared<features::ChunkingInterceptor>("AwsSmithyClientBase",
116116
m_httpClient->IsDefaultAwsHttpClient() ? Aws::Client::HttpClientChunkedMode::DEFAULT : m_clientConfig->httpClientChunkedMode,
117117
m_clientConfig->awsChunkedBufferSize)
118-
}),
119-
m_enableNewRetries{Aws::Utils::StringUtils::ToLower(Aws::Environment::GetEnv("AWS_NEW_RETRIES_2026").c_str()) == "true"}
118+
})
120119
{
121120

122121
baseInit();

‎src/aws-cpp-sdk-core/source/client/AWSClient.cpp‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <aws/core/client/ClientConfiguration.h>
1515
#include <aws/core/client/CoreErrors.h>
1616
#include <aws/core/client/RetryStrategy.h>
17+
#include <aws/core/internal/RetryStrategyImpl.h>
1718
#include <aws/core/client/RequestCompression.h>
1819
#include <aws/core/http/HttpClient.h>
1920
#include <aws/core/http/HttpClientFactory.h>
@@ -177,7 +178,7 @@ AWSClient::AWSClient(const Aws::Client::ClientConfiguration& configuration,
177178
m_httpClient->IsDefaultAwsHttpClient() ? Aws::Client::HttpClientChunkedMode::DEFAULT : configuration.httpClientChunkedMode,
178179
configuration.awsChunkedBufferSize),
179180
m_userAgentInterceptor},
180-
m_enableNewRetries{Aws::Utils::StringUtils::ToLower(Aws::Environment::GetEnv("AWS_NEW_RETRIES_2026").c_str()) == "true"},
181+
m_enableNewRetries{Aws::Client::Internal::UsesRetryBehavior21(m_retryStrategy.get())},
181182
m_disableExpectHeader(configuration.disableExpectHeader)
182183
{
183184
}
@@ -209,7 +210,7 @@ AWSClient::AWSClient(const Aws::Client::ClientConfiguration& configuration,
209210
m_httpClient->IsDefaultAwsHttpClient() ? Aws::Client::HttpClientChunkedMode::DEFAULT : configuration.httpClientChunkedMode,
210211
configuration.awsChunkedBufferSize),
211212
m_userAgentInterceptor},
212-
m_enableNewRetries{Aws::Utils::StringUtils::ToLower(Aws::Environment::GetEnv("AWS_NEW_RETRIES_2026").c_str()) == "true"},
213+
m_enableNewRetries{Aws::Client::Internal::UsesRetryBehavior21(m_retryStrategy.get())},
213214
m_disableExpectHeader(configuration.disableExpectHeader)
214215
{
215216
}

‎src/aws-cpp-sdk-core/source/client/AWSErrorMarshaller.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <aws/core/client/AWSError.h>
1212
#include <aws/core/client/CoreErrors.h>
1313
#include <aws/core/utils/cbor/CborValue.h>
14+
#include <aws/core/internal/RetryStrategyImpl.h>
1415

1516
using namespace Aws::Utils::Logging;
1617
using namespace Aws::Utils::Json;
@@ -104,6 +105,7 @@ AWSError<CoreErrors> JsonErrorMarshaller::BuildAWSError(const std::shared_ptr<Ht
104105

105106
error.SetResponseHeaders(httpResponse->GetHeaders());
106107
error.SetResponseCode(httpResponse->GetResponseCode());
108+
Aws::Client::Internal::ClassifyUnmodeledTooManyRequests(error);
107109
error.SetRemoteHostIpAddress(httpResponse->GetOriginatingRequest().GetResolvedRemoteHost());
108110
AWS_LOGSTREAM_ERROR(AWS_ERROR_MARSHALLER_LOG_TAG, error);
109111
return error;
@@ -197,6 +199,7 @@ AWSError<CoreErrors> XmlErrorMarshaller::BuildAWSError(const std::shared_ptr<Htt
197199

198200
error.SetResponseHeaders(httpResponse->GetHeaders());
199201
error.SetResponseCode(httpResponse->GetResponseCode());
202+
Aws::Client::Internal::ClassifyUnmodeledTooManyRequests(error);
200203
error.SetRemoteHostIpAddress(httpResponse->GetOriginatingRequest().GetResolvedRemoteHost());
201204
AWS_LOGSTREAM_ERROR(AWS_ERROR_MARSHALLER_LOG_TAG, error);
202205
return error;
@@ -522,6 +525,7 @@ AWSError<CoreErrors> RpcV2ErrorMarshaller::BuildAWSError(const std::shared_ptr<H
522525

523526
error.SetResponseHeaders(httpResponse->GetHeaders());
524527
error.SetResponseCode(httpResponse->GetResponseCode());
528+
Aws::Client::Internal::ClassifyUnmodeledTooManyRequests(error);
525529
error.SetRemoteHostIpAddress(httpResponse->GetOriginatingRequest().GetResolvedRemoteHost());
526530
AWS_LOGSTREAM_ERROR(AWS_ERROR_MARSHALLER_LOG_TAG, error);
527531
return error;

0 commit comments

Comments
 (0)