-
Notifications
You must be signed in to change notification settings - Fork 997
Retries fixes #6920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dagnir
merged 1 commit into
feature/master/2026-new-retries
from
dongie/2026-new-retries/maxattempts-limit-exceeded-fixes
Apr 29, 2026
Merged
Retries fixes #6920
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
core/aws-core/src/test/java/software/amazon/awssdk/awscore/retry/AwsRetryStrategyTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package software.amazon.awssdk.awscore.retry; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
|
||
| import com.google.common.base.Supplier; | ||
| import java.time.Duration; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.CsvSource; | ||
| import software.amazon.awssdk.awscore.exception.AwsErrorDetails; | ||
| import software.amazon.awssdk.awscore.exception.AwsServiceException; | ||
| import software.amazon.awssdk.retries.StandardRetryStrategy; | ||
| import software.amazon.awssdk.retries.api.AcquireInitialTokenRequest; | ||
| import software.amazon.awssdk.retries.api.RefreshRetryTokenRequest; | ||
| import software.amazon.awssdk.retries.api.RetryToken; | ||
| import software.amazon.awssdk.retries.api.TokenAcquisitionFailedException; | ||
| import software.amazon.awssdk.retries.internal.DefaultRetryToken; | ||
|
|
||
| public class AwsRetryStrategyTest { | ||
|
Check warning on line 34 in core/aws-core/src/test/java/software/amazon/awssdk/awscore/retry/AwsRetryStrategyTest.java
|
||
|
|
||
| @ParameterizedTest | ||
| @CsvSource({"true", "false"}) | ||
| void standardRetryStrategy_limitExceededException_retryBehaviorCorrect(boolean newRetries2026Enabled) { | ||
| StandardRetryStrategy strategy = AwsRetryStrategy.standardRetryStrategy(newRetries2026Enabled); | ||
|
|
||
| RetryToken token = strategy.acquireInitialToken(AcquireInitialTokenRequest.create("test")).token(); | ||
| RefreshRetryTokenRequest refresh = RefreshRetryTokenRequest.builder() | ||
| .failure(createTestException("LimitExceededException")) | ||
| .token(token) | ||
| .build(); | ||
|
|
||
| if (newRetries2026Enabled) { | ||
| assertThat(strategy.refreshRetryToken(refresh).delay()).isGreaterThanOrEqualTo(Duration.ZERO); | ||
| } else { | ||
| assertThatThrownBy(() -> strategy.refreshRetryToken(refresh)) | ||
| .isInstanceOf(TokenAcquisitionFailedException.class) | ||
| .matches(e -> { | ||
| TokenAcquisitionFailedException acquireException = (TokenAcquisitionFailedException) e; | ||
| DefaultRetryToken exceptionToken = (DefaultRetryToken) acquireException.token(); | ||
| return exceptionToken.state() == DefaultRetryToken.TokenState.NON_RETRYABLE_EXCEPTION; | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @CsvSource({"Throttling", | ||
| "ThrottlingException", | ||
| "ThrottledException", | ||
| "RequestThrottledException", | ||
| "TooManyRequestsException", | ||
| "ProvisionedThroughputExceededException", | ||
| "TransactionInProgressException", | ||
| "RequestLimitExceeded", | ||
| "BandwidthLimitExceeded", | ||
| "LimitExceededException", | ||
| "RequestThrottled", | ||
| "SlowDown", | ||
| "PriorRequestNotComplete", | ||
| "EC2ThrottledException"}) | ||
| void standardRetryStrategy_retry21_throttlingBehaviorCorrect(String errorCode) { | ||
| AwsServiceException exception = createTestException(errorCode); | ||
|
|
||
| for (int i = 0; i < 128; ++i) { | ||
| StandardRetryStrategy strategy = AwsRetryStrategy.standardRetryStrategy(true); | ||
|
|
||
| RetryToken token = strategy.acquireInitialToken(AcquireInitialTokenRequest.create("test")).token(); | ||
| RefreshRetryTokenRequest refresh = RefreshRetryTokenRequest.builder() | ||
| .token(token) | ||
| .failure(exception) | ||
| .build(); | ||
| Duration delay = strategy.refreshRetryToken(refresh).delay(); | ||
|
|
||
| assertThat(delay).isBetween(Duration.ZERO, Duration.ofMillis(1000)); | ||
| } | ||
| } | ||
|
|
||
| private static AwsServiceException createTestException(String errorCode) { | ||
| AwsErrorDetails details = AwsErrorDetails.builder() | ||
| .errorCode(errorCode) | ||
| .build(); | ||
| return AwsServiceException.builder().awsErrorDetails(details).build(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...dk-core/src/main/java/software/amazon/awssdk/core/internal/retry/MaxAttemptsResolver.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package software.amazon.awssdk.core.internal.retry; | ||
|
|
||
| import java.util.Optional; | ||
| import java.util.function.Supplier; | ||
| import software.amazon.awssdk.annotations.SdkInternalApi; | ||
| import software.amazon.awssdk.core.SdkSystemSetting; | ||
| import software.amazon.awssdk.profiles.ProfileFile; | ||
| import software.amazon.awssdk.profiles.ProfileFileSystemSetting; | ||
| import software.amazon.awssdk.profiles.ProfileProperty; | ||
| import software.amazon.awssdk.utils.OptionalUtils; | ||
|
|
||
| /** | ||
| * Resolves the retry max attempts from {@link SdkSystemSetting#AWS_MAX_ATTEMPTS} and {@link ProfileProperty#MAX_ATTEMPTS}. | ||
| */ | ||
| @SdkInternalApi | ||
| public class MaxAttemptsResolver { | ||
| private Supplier<ProfileFile> profileFile; | ||
| private String profileName; | ||
|
|
||
| /** | ||
| * Configure the profile file that should be used when determining the max attempts. The supplier is only consulted | ||
| * if a higher-priority determinant (e.g. environment variables) does not find the setting. | ||
| */ | ||
| public MaxAttemptsResolver profileFile(Supplier<ProfileFile> profileFile) { | ||
| this.profileFile = profileFile; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Configure the profile file name should be used when determining the max attempts. | ||
| */ | ||
| public MaxAttemptsResolver profileName(String profileName) { | ||
| this.profileName = profileName; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Resolve the max attempts based on the configured values. If not configured, returns {@code null}. | ||
| */ | ||
| public Integer resolve() { | ||
| return OptionalUtils.firstPresent(fromSystemSettings(), () -> fromProfileFile(profileFile, profileName)) | ||
| .orElse(null); | ||
| } | ||
|
|
||
|
|
||
| private static Optional<Integer> fromSystemSettings() { | ||
| return SdkSystemSetting.AWS_MAX_ATTEMPTS.getIntegerValue(); | ||
| } | ||
|
|
||
| private static Optional<Integer> fromProfileFile(Supplier<ProfileFile> profileFile, String profileName) { | ||
| profileFile = profileFile != null ? profileFile : ProfileFile::defaultProfileFile; | ||
| profileName = profileName != null ? profileName : ProfileFileSystemSetting.AWS_PROFILE.getStringValueOrThrow(); | ||
| return profileFile.get() | ||
| .profile(profileName) | ||
| .flatMap(p -> p.property(ProfileProperty.MAX_ATTEMPTS)) | ||
| .map(Integer::parseInt); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.