Skip to content

Commit 3ca5166

Browse files
committed
adding logging and dry
1 parent d960d2a commit 3ca5166

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ std::shared_ptr<RetryStrategy> InitRetryStrategy(int maxAttempts, Aws::String re
552552
{
553553
retryMode = Aws::Config::GetCachedConfigValue("retry_mode");
554554
}
555-
if (Aws::Environment::GetEnv("AWS_NEW_RETRIES_2026") == "true" && retryMode.empty())
555+
if (Aws::Utils::StringUtils::ToLower(Aws::Environment::GetEnv("AWS_NEW_RETRIES_2026").c_str()) == "true" && retryMode.empty())
556556
{
557557
retryMode = "standard";
558558
}

src/aws-cpp-sdk-core/source/client/RetryStrategy.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111
#include <aws/core/utils/Outcome.h>
1212
#include <aws/core/utils/StringUtils.h>
1313
#include <aws/core/utils/local/Random.h>
14+
#include <aws/core/utils/logging/LogMacros.h>
1415

1516
using namespace Aws::Utils::Threading;
1617

18+
static const char RETRY_STRATEGY_TAG[] = "StandardRetryStrategy";
19+
1720
namespace Aws
1821
{
1922
namespace Client
@@ -22,6 +25,11 @@ namespace Aws
2225
static const int RETRY_COST = 5;
2326
static const int TIMEOUT_RETRY_COST = 10;
2427

28+
static bool IsNewRetriesEnabled()
29+
{
30+
return Aws::Utils::StringUtils::ToLower(Aws::Environment::GetEnv("AWS_NEW_RETRIES_2026").c_str()) == "true";
31+
}
32+
2533
struct StandardRetryStrategy::RetryImpl
2634
{
2735
virtual ~RetryImpl() = default;
@@ -54,7 +62,12 @@ namespace Aws
5462
auto it = headers.find("x-amz-retry-after");
5563
if (it != headers.end())
5664
{
57-
double headerSec = static_cast<double>(Aws::Utils::StringUtils::ConvertToInt64(it->second.c_str())) / 1000.0;
65+
long long headerMs = Aws::Utils::StringUtils::ConvertToInt64(it->second.c_str());
66+
if (headerMs < 0)
67+
{
68+
AWS_LOGSTREAM_DEBUG(RETRY_STRATEGY_TAG, "Ignoring invalid x-amz-retry-after value: " << it->second);
69+
}
70+
double headerSec = static_cast<double>(headerMs) / 1000.0;
5871
double clamped = (std::max)(t_i, (std::min)(headerSec, 5.0 + t_i));
5972
return static_cast<long>(clamped * 1000.0);
6073
}
@@ -66,7 +79,7 @@ namespace Aws
6679

6780
static Aws::UniquePtr<StandardRetryStrategy::RetryImpl> CreateRetryImpl()
6881
{
69-
if (Aws::Environment::GetEnv("AWS_NEW_RETRIES_2026") == "true")
82+
if (IsNewRetriesEnabled())
7083
{
7184
return Aws::MakeUnique<NewRetriesImpl>("StandardRetryStrategy");
7285
}
@@ -75,7 +88,7 @@ namespace Aws
7588

7689
static std::shared_ptr<RetryQuotaContainer> CreateQuotaContainer()
7790
{
78-
if (Aws::Environment::GetEnv("AWS_NEW_RETRIES_2026") == "true")
91+
if (IsNewRetriesEnabled())
7992
{
8093
return Aws::MakeShared<ThrottleBasedRetryQuotaContainer>("StandardRetryStrategy");
8194
}

0 commit comments

Comments
 (0)