Skip to content

Commit 2601336

Browse files
authored
reties_2026 gating follow-ups (#3969)
* Fix AWS_NEW_RETRIES_2026 gating issues * Add changelog fragment
1 parent 446eb90 commit 2601336

6 files changed

Lines changed: 94 additions & 42 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "bugfix",
3+
"category": "aws-cpp-sdk-core",
4+
"contributor": "pulimsr",
5+
"description": "Fix AWS_NEW_RETRIES_2026 gating: restore DefaultRetryStrategy fallback when the flag is off, read the flag case-insensitively in smithy clients, and let AWS_MAX_ATTEMPTS override the DynamoDB default when the flag is on"
6+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ namespace client
267267
ResponseHandlerFunc&& responseHandler,
268268
EndpointUpdateCallback&& endpointCallback
269269
) const;
270-
bool m_enableNewRetries;
270+
bool m_enableNewRetries = false;
271271
};
272272
} // namespace client
273273
} // namespace smithy

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

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -617,33 +617,47 @@ std::shared_ptr<RetryStrategy> InitRetryStrategy(int maxAttempts, Aws::String re
617617
}
618618
else
619619
{
620-
if (Aws::Utils::StringUtils::ToLower(Aws::Environment::GetEnv("AWS_NEW_RETRIES_2026").c_str()) != "true")
621-
{
622-
if (maxAttempts < 0)
623-
{
624-
retryStrategy = Aws::MakeShared<StandardRetryStrategy>(CLIENT_CONFIG_TAG);
625-
}
626-
else
627-
{
628-
retryStrategy = Aws::MakeShared<StandardRetryStrategy>(CLIENT_CONFIG_TAG, maxAttempts);
629-
}
630-
}
631-
else
632-
{
633-
retryStrategy = Aws::MakeShared<DefaultRetryStrategy>(CLIENT_CONFIG_TAG);
634-
}
620+
retryStrategy = Aws::MakeShared<DefaultRetryStrategy>(CLIENT_CONFIG_TAG);
635621
}
636622

637623
return retryStrategy;
638624
}
639625

626+
static int ResolveConfiguredMaxAttempts()
627+
{
628+
Aws::String maxAttemptsString = Aws::Environment::GetEnv("AWS_MAX_ATTEMPTS");
629+
if (maxAttemptsString.empty())
630+
{
631+
maxAttemptsString = Aws::Config::GetCachedConfigValue("max_attempts");
632+
}
633+
// In case users specify 0 explicitly to disable retry.
634+
if (maxAttemptsString == "0")
635+
{
636+
return 0;
637+
}
638+
int maxAttempts = static_cast<int>(Aws::Utils::StringUtils::ConvertToInt32(maxAttemptsString.c_str()));
639+
if (maxAttempts == 0)
640+
{
641+
AWS_LOGSTREAM_INFO(CLIENT_CONFIG_TAG, "Retry Strategy will use the default max attempts.");
642+
return -1;
643+
}
644+
return maxAttempts;
645+
}
646+
640647
std::shared_ptr<RetryStrategy> InitRetryStrategy(int maxAttempts, Aws::String retryMode, double transientBackoffBaseSec) {
641648
if (Aws::Utils::StringUtils::ToLower(Aws::Environment::GetEnv("AWS_NEW_RETRIES_2026").c_str()) != "true")
642649
{
643650
// Gate is off: ignore service-specific tuning, use default behavior
644651
return InitRetryStrategy(retryMode);
645652
}
646653

654+
// maxAttempts is a service default. A max attempts value the customer configured wins.
655+
const int configuredMaxAttempts = ResolveConfiguredMaxAttempts();
656+
if (configuredMaxAttempts >= 0)
657+
{
658+
maxAttempts = configuredMaxAttempts;
659+
}
660+
647661
// Only standard mode honors a service-specific backoff base; other modes are unaffected,
648662
// so they go through the default-base path.
649663
if (ResolveRetryMode(retryMode) != "standard")
@@ -657,28 +671,7 @@ std::shared_ptr<RetryStrategy> InitRetryStrategy(int maxAttempts, Aws::String re
657671

658672
std::shared_ptr<RetryStrategy> InitRetryStrategy(Aws::String retryMode)
659673
{
660-
int maxAttempts = 0;
661-
Aws::String maxAttemptsString = Aws::Environment::GetEnv("AWS_MAX_ATTEMPTS");
662-
if (maxAttemptsString.empty())
663-
{
664-
maxAttemptsString = Aws::Config::GetCachedConfigValue("max_attempts");
665-
}
666-
// In case users specify 0 explicitly to disable retry.
667-
if (maxAttemptsString == "0")
668-
{
669-
maxAttempts = 0;
670-
}
671-
else
672-
{
673-
maxAttempts = static_cast<int>(Aws::Utils::StringUtils::ConvertToInt32(maxAttemptsString.c_str()));
674-
if (maxAttempts == 0)
675-
{
676-
AWS_LOGSTREAM_INFO(CLIENT_CONFIG_TAG, "Retry Strategy will use the default max attempts.");
677-
maxAttempts = -1;
678-
}
679-
}
680-
681-
return InitRetryStrategy(maxAttempts, retryMode);
674+
return InitRetryStrategy(ResolveConfiguredMaxAttempts(), retryMode);
682675
}
683676

684677
Aws::String ClientConfiguration::LoadConfigFromEnvOrProfile(const Aws::String& envKey,

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ void AwsSmithyClientBase::baseCopyAssign(const AwsSmithyClientBase& other,
108108
std::shared_ptr<Aws::Client::AWSErrorMarshaller> errorMarshaller) {
109109
m_serviceName = other.m_serviceName;
110110
m_serviceUserAgentName = other.m_serviceUserAgentName;
111+
m_enableNewRetries = other.m_enableNewRetries;
111112
m_httpClient = std::move(httpClient);
112113
m_errorMarshaller = std::move(errorMarshaller);
113114

@@ -129,6 +130,7 @@ void AwsSmithyClientBase::baseMoveAssign(AwsSmithyClientBase&& other) {
129130
m_errorMarshaller = std::move(other.m_errorMarshaller);
130131
m_interceptors = std::move(other.m_interceptors);
131132
m_userAgentInterceptor = std::move(other.m_userAgentInterceptor);
133+
m_enableNewRetries = other.m_enableNewRetries;
132134
}
133135

134136
std::shared_ptr<Aws::Http::HttpRequest>
@@ -335,10 +337,7 @@ std::shared_ptr<AwsSmithyClientAsyncRequestContext> AwsSmithyClientBase::CreateR
335337
}
336338
pRequestCtx->m_requestInfo.attempt = 1;
337339
pRequestCtx->m_attemptSkew = m_clientSkew->Load();
338-
pRequestCtx->m_requestInfo.maxAttempts =
339-
Aws::Environment::GetEnv("AWS_NEW_RETRIES_2026") == "true"
340-
? m_clientConfig->retryStrategy->GetMaxAttempts()
341-
: 0;
340+
pRequestCtx->m_requestInfo.maxAttempts = m_enableNewRetries ? m_clientConfig->retryStrategy->GetMaxAttempts() : 0;
342341
pRequestCtx->m_interceptorContext = Aws::MakeShared<InterceptorContext>(AWS_SMITHY_CLIENT_LOG, *request);
343342
pRequestCtx->m_responseHandler = std::move(responseHandler);
344343
pRequestCtx->m_authResolvedCallback = std::move(authCallback);

‎tests/aws-cpp-sdk-core-tests/aws/client/RetryStrategyTest.cpp‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
#include <aws/testing/AwsCppSdkGTestSuite.h>
88
#include <aws/testing/platform/PlatformTesting.h>
99
#include <aws/core/client/AWSError.h>
10+
#include <aws/core/client/ClientConfiguration.h>
1011
#include <aws/core/client/CoreErrors.h>
1112
#include <aws/core/client/RetryStrategy.h>
13+
#include <aws/core/config/ConfigAndCredentialsCacheManager.h>
1214
#include <aws/core/http/URI.h>
1315
#include <aws/core/http/HttpClientFactory.h>
1416
#include <aws/core/http/standard/StandardHttpRequest.h>
@@ -317,3 +319,40 @@ TEST_F(NewRetriesStrategyTest, DynamoDBBackoffBase)
317319
ASSERT_GE(delay, 0);
318320
ASSERT_LE(delay, 1000);
319321
}
322+
323+
class InitRetryStrategyTest : public Aws::Testing::AwsCppSdkGTestSuite
324+
{
325+
protected:
326+
void SetUp() override { Aws::Config::ReloadCachedConfigFile(); }
327+
void TearDown() override { Aws::Config::ReloadCachedConfigFile(); }
328+
};
329+
330+
TEST_F(InitRetryStrategyTest, GateOffUnsetRetryModeUsesDefaultRetryStrategy)
331+
{
332+
Aws::Environment::EnvironmentRAII env{{{"AWS_NEW_RETRIES_2026", ""},
333+
{"AWS_RETRY_MODE", ""},
334+
{"AWS_MAX_ATTEMPTS", ""},
335+
{"AWS_CONFIG_FILE", "/nonexistent/retry-strategy-test-config"}}};
336+
Aws::Config::ReloadCachedConfigFile();
337+
338+
auto retryStrategy = InitRetryStrategy();
339+
ASSERT_TRUE(retryStrategy);
340+
ASSERT_STREQ("default", retryStrategy->GetStrategyName());
341+
ASSERT_EQ(11, retryStrategy->GetMaxAttempts());
342+
}
343+
344+
TEST_F(InitRetryStrategyTest, ConfiguredMaxAttemptsOverridesServiceDefault)
345+
{
346+
for (const auto& testCase : {std::make_pair("", 4L), std::make_pair("2", 2L), std::make_pair("0", 0L)})
347+
{
348+
Aws::Environment::EnvironmentRAII env{{{"AWS_NEW_RETRIES_2026", "true"},
349+
{"AWS_RETRY_MODE", ""},
350+
{"AWS_MAX_ATTEMPTS", testCase.first},
351+
{"AWS_CONFIG_FILE", "/nonexistent/retry-strategy-test-config"}}};
352+
Aws::Config::ReloadCachedConfigFile();
353+
354+
auto retryStrategy = InitRetryStrategy(4, "", 0.025);
355+
ASSERT_TRUE(retryStrategy);
356+
ASSERT_EQ(testCase.second, retryStrategy->GetMaxAttempts()) << "AWS_MAX_ATTEMPTS=" << testCase.first;
357+
}
358+
}

‎tests/aws-cpp-sdk-core-tests/smithy/client/AsyncSmithyClientTest.cpp‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <aws/core/client/ClientConfiguration.h>
1313
#include <aws/core/client/CoreErrors.h>
1414
#include <aws/core/client/DefaultRetryStrategy.h>
15+
#include <aws/core/client/RetryStrategy.h>
1516
#include <aws/core/endpoint/AWSEndpoint.h>
1617
#include <aws/core/endpoint/EndpointProviderBase.h>
1718
#include <aws/core/http/HttpClientFactory.h>
@@ -300,4 +301,18 @@ namespace
300301
ASSERT_LT(elapsed, std::chrono::milliseconds(LONG_POLL_DELAY_MS));
301302
#endif
302303
}
304+
305+
TEST_F(AsyncSmithyClientTest, NewRetriesFlagIsCaseInsensitive)
306+
{
307+
Aws::Environment::EnvironmentRAII env{{{"AWS_NEW_RETRIES_2026", "TRUE"}}};
308+
client = MakeClient(Aws::MakeShared<StandardRetryStrategy>(ALLOCATION_TAG, 3));
309+
mockHttpClient->AddResponseToReturn(MakeSuccessResponse());
310+
311+
auto outcome = RunAndCapture();
312+
313+
ASSERT_TRUE(outcome.IsSuccess());
314+
const auto& requests = mockHttpClient->GetAllRequestsMade();
315+
ASSERT_EQ(1u, requests.size());
316+
ASSERT_NE(Aws::String::npos, requests[0].GetHeaders()[Aws::Http::SDK_REQUEST_HEADER].find("max=3"));
317+
}
303318
}

0 commit comments

Comments
 (0)