Skip to content

Commit 8e31b75

Browse files
committed
New Max Attemp Retry Strategy
1 parent 7eb811a commit 8e31b75

File tree

3 files changed

+8
-16
lines changed

3 files changed

+8
-16
lines changed

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ namespace Aws
501501
* Number of total attempts to make when retrieving data from IMDS. Default 1.
502502
*/
503503
long metadataServiceNumAttempts = 1;
504-
504+
505505
/**
506506
* Timeout in seconds when retrieving data from IMDS. Default 1.
507507
*/
@@ -512,20 +512,15 @@ namespace Aws
512512
*/
513513
std::shared_ptr<RetryStrategy> imdsRetryStrategy;
514514
} imdsConfig;
515-
516-
/**
517-
* Region to use for calls
518-
*/
519-
Aws::String region;
520515
}credentialProviderConfig;
521516
};
522517

523518
/**
524519
* A helper function to initialize a retry strategy.
525520
* Default is DefaultRetryStrategy (i.e. exponential backoff)
526521
*/
527-
AWS_CORE_API std::shared_ptr<RetryStrategy> InitRetryStrategy(Aws::String retryMode = "");
528-
AWS_CORE_API std::shared_ptr<RetryStrategy> InitRetryStrategy(int maxRetries, Aws::String retryMode = "");
522+
std::shared_ptr<RetryStrategy> InitRetryStrategy(Aws::String retryMode = "");
523+
std::shared_ptr<RetryStrategy> InitRetryStrategy(int maxAttempts, Aws::String retryMode = "");
529524

530525
/**
531526
* A helper function to compute a user agent

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,9 @@ void setConfigFromEnvOrProfile(ClientConfiguration &config)
316316
long attempts = static_cast<long>(Aws::Utils::StringUtils::ConvertToInt32(numAttemptsStr.c_str()));
317317
config.credentialProviderConfig.imdsConfig.metadataServiceNumAttempts = attempts;
318318

319-
// Ensure retry strategy is set using factory pattern
320-
if (!config.retryStrategy) {
321-
config.retryStrategy = config.configFactories.retryStrategyCreateFn();
322-
}
319+
// Initialize IMDS-specific retry strategy with configured number of attempts
320+
// Uses default retry mode with the specified max attempts from metadata_service_num_attempts
321+
config.credentialProviderConfig.imdsConfig.imdsRetryStrategy = InitRetryStrategy(attempts, "");
323322
}
324323

325324
ClientConfiguration::ClientConfiguration()

src/aws-cpp-sdk-core/source/internal/AWSHttpResourceClient.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ namespace Aws
8282
AWSHttpResourceClient::AWSHttpResourceClient(const Aws::Client::ClientConfiguration& clientConfiguration, const char* logtag)
8383
: m_logtag(logtag),
8484
m_userAgent(Aws::Client::ComputeUserAgentString(&clientConfiguration)),
85-
m_retryStrategy(clientConfiguration.retryStrategy),
85+
m_retryStrategy(clientConfiguration.retryStrategy ? clientConfiguration.retryStrategy : clientConfiguration.configFactories.retryStrategyCreateFn()),
8686
m_httpClient(nullptr)
8787
{
8888
AWS_LOGSTREAM_INFO(m_logtag.c_str(),
@@ -213,10 +213,8 @@ namespace Aws
213213
[&credentialConfig]() -> ClientConfiguration{
214214
Aws::Client::ClientConfiguration clientConfig;
215215
clientConfig.credentialProviderConfig = credentialConfig;
216-
clientConfig.connectTimeoutMs = credentialConfig.imdsConfig.metadataServiceTimeout * 1000;
217216
clientConfig.requestTimeoutMs = credentialConfig.imdsConfig.metadataServiceTimeout * 1000;
218-
clientConfig.retryStrategy = Aws::MakeShared<DefaultRetryStrategy>(
219-
RESOURCE_CLIENT_CONFIGURATION_ALLOCATION_TAG, credentialConfig.imdsConfig.metadataServiceNumAttempts - 1, 1000);
217+
clientConfig.retryStrategy = credentialConfig.imdsConfig.imdsRetryStrategy;
220218
return clientConfig;
221219
}(),
222220
EC2_METADATA_CLIENT_LOG_TAG),

0 commit comments

Comments
 (0)