Skip to content

Commit dcf02e6

Browse files
committed
New Max Attemp Retry Strategy
1 parent 62ce188 commit dcf02e6

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,11 @@ namespace Aws
506506
* Timeout in seconds when retrieving data from IMDS. Default 1.
507507
*/
508508
long metadataServiceTimeout = 1;
509+
510+
/**
511+
* Retry Strategy for IMDS
512+
*/
513+
std::shared_ptr<RetryStrategy> imdsRetryStrategy;
509514
} imdsConfig;
510515
}credentialProviderConfig;
511516
};
@@ -515,6 +520,7 @@ namespace Aws
515520
* Default is DefaultRetryStrategy (i.e. exponential backoff)
516521
*/
517522
std::shared_ptr<RetryStrategy> InitRetryStrategy(Aws::String retryMode = "");
523+
std::shared_ptr<RetryStrategy> InitRetryStrategy(int maxAttempts, Aws::String retryMode = "");
518524

519525
/**
520526
* 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
@@ -315,10 +315,9 @@ void setConfigFromEnvOrProfile(ClientConfiguration &config)
315315
long attempts = static_cast<long>(Aws::Utils::StringUtils::ConvertToInt32(numAttemptsStr.c_str()));
316316
config.credentialProviderConfig.imdsConfig.metadataServiceNumAttempts = attempts;
317317

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

324323
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)