-
Notifications
You must be signed in to change notification settings - Fork 997
Retry on IDPCommunicationError #6923
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 2 commits into
feature/master/2026-new-retries
from
dongie/2026-new-retries/sts-retry-fix
Apr 30, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
68 changes: 68 additions & 0 deletions
68
...ices/sts/src/main/java/software/amazon/awssdk/services/sts/internal/StsRetryStrategy.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,68 @@ | ||
| /* | ||
| * 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.services.sts.internal; | ||
|
|
||
| import software.amazon.awssdk.annotations.SdkInternalApi; | ||
| import software.amazon.awssdk.awscore.retry.AwsRetryStrategy; | ||
| import software.amazon.awssdk.core.client.config.SdkClientConfiguration; | ||
| import software.amazon.awssdk.core.client.config.SdkClientOption; | ||
| import software.amazon.awssdk.core.retry.NewRetries2026Resolver; | ||
| import software.amazon.awssdk.core.retry.RetryMode; | ||
| import software.amazon.awssdk.retries.api.RetryStrategy; | ||
| import software.amazon.awssdk.services.sts.model.IdpCommunicationErrorException; | ||
|
|
||
| /** | ||
| * Specialized retry strategy resolution for STS to enable retrying for {@link IdpCommunicationErrorException}. | ||
| */ | ||
| @SdkInternalApi | ||
| public final class StsRetryStrategy { | ||
|
|
||
| private StsRetryStrategy() { | ||
| } | ||
|
|
||
| public static RetryStrategy resolveRetryStrategy(SdkClientConfiguration config) { | ||
| RetryStrategy configuredRetryStrategy = config.option(SdkClientOption.RETRY_STRATEGY); | ||
| if (configuredRetryStrategy != null) { | ||
| return configuredRetryStrategy; | ||
| } | ||
|
|
||
| // Just return null and let the normal retry strategy resolution occur | ||
| if (!isNewRetries2026Enabled(config)) { | ||
| return null; | ||
| } | ||
|
|
||
| RetryMode retryMode = resolveRetryMode(config); | ||
|
|
||
| return AwsRetryStrategy.forRetryMode(retryMode, true) | ||
| .toBuilder() | ||
| .retryOnException(IdpCommunicationErrorException.class) | ||
| .build(); | ||
| } | ||
|
|
||
| private static RetryMode resolveRetryMode(SdkClientConfiguration config) { | ||
| return RetryMode.resolver() | ||
| .profileFile(config.option(SdkClientOption.PROFILE_FILE_SUPPLIER)) | ||
| .profileName(config.option(SdkClientOption.PROFILE_NAME)) | ||
| .defaultRetryMode(config.option(SdkClientOption.DEFAULT_RETRY_MODE)) | ||
| .defaultNewRetries2026(config.option(SdkClientOption.DEFAULT_NEW_RETRIES_2026)) | ||
| .resolve(); | ||
| } | ||
|
|
||
| private static boolean isNewRetries2026Enabled(SdkClientConfiguration config) { | ||
| Boolean defaultNewRetries2026 = config.option(SdkClientOption.DEFAULT_NEW_RETRIES_2026); | ||
| return new NewRetries2026Resolver().defaultNewRetries2026(defaultNewRetries2026).resolve(); | ||
| } | ||
| } |
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
111 changes: 111 additions & 0 deletions
111
.../sts/src/test/java/software/amazon/awssdk/services/sts/internal/StsRetryStrategyTest.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,111 @@ | ||
| /* | ||
| * 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.services.sts.internal; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.mockito.Mockito.mock; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.stream.Stream; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.Arguments; | ||
| import org.junit.jupiter.params.provider.MethodSource; | ||
| import software.amazon.awssdk.awscore.exception.AwsErrorDetails; | ||
| import software.amazon.awssdk.core.SdkSystemSetting; | ||
| import software.amazon.awssdk.core.client.config.SdkClientConfiguration; | ||
| import software.amazon.awssdk.core.client.config.SdkClientOption; | ||
| import software.amazon.awssdk.retries.AdaptiveRetryStrategy; | ||
| import software.amazon.awssdk.retries.LegacyRetryStrategy; | ||
| 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.RetryStrategy; | ||
| import software.amazon.awssdk.retries.api.RetryToken; | ||
| import software.amazon.awssdk.services.sts.model.IdpCommunicationErrorException; | ||
|
|
||
| public class StsRetryStrategyTest { | ||
| @Test | ||
| void resolveRetryStrategy_preexistingStrategy_returnsPreexisting() { | ||
| RetryStrategy strategy = mock(RetryStrategy.class); | ||
| SdkClientConfiguration config = SdkClientConfiguration.builder() | ||
| .option(SdkClientOption.RETRY_STRATEGY, strategy) | ||
| .build(); | ||
|
|
||
| assertThat(StsRetryStrategy.resolveRetryStrategy(config)).isSameAs(strategy); | ||
| } | ||
|
|
||
| @Test | ||
| void resolveRetryStrategy_defaultNewRetries2026False_returnsNull() { | ||
| SdkClientConfiguration config = SdkClientConfiguration.builder() | ||
| .option(SdkClientOption.DEFAULT_NEW_RETRIES_2026, false) | ||
| .build(); | ||
|
|
||
| assertThat(StsRetryStrategy.resolveRetryStrategy(config)).isNull(); | ||
| } | ||
|
|
||
| @Test | ||
| void resolveRetryStrategy_newRetries2026False_returnsNull() { | ||
| System.setProperty(SdkSystemSetting.AWS_NEW_RETRIES_2026.property(), "false"); | ||
| try { | ||
| SdkClientConfiguration config = SdkClientConfiguration.builder().build(); | ||
| assertThat(StsRetryStrategy.resolveRetryStrategy(config)).isNull(); | ||
| } finally { | ||
| System.clearProperty(SdkSystemSetting.AWS_NEW_RETRIES_2026.property()); | ||
| } | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @MethodSource("retryModeResolutionCases") | ||
| void resolveRetryStrategy_returnsCorrectStrategyBasedOnMode(String mode, Class<?> expected) { | ||
| System.setProperty(SdkSystemSetting.AWS_RETRY_MODE.property(), mode); | ||
| System.setProperty(SdkSystemSetting.AWS_NEW_RETRIES_2026.property(), "true"); | ||
| try { | ||
| SdkClientConfiguration config = SdkClientConfiguration.builder().build(); | ||
| RetryStrategy resolved = StsRetryStrategy.resolveRetryStrategy(config); | ||
| assertThat(resolved).isInstanceOf(expected); | ||
| assertRetriesOnIdpCommunicationException(resolved); | ||
| } finally { | ||
| System.clearProperty(SdkSystemSetting.AWS_RETRY_MODE.property()); | ||
| System.clearProperty(SdkSystemSetting.AWS_NEW_RETRIES_2026.property()); | ||
| } | ||
| } | ||
|
|
||
| void assertRetriesOnIdpCommunicationException(RetryStrategy strategy) { | ||
| RetryToken token = strategy.acquireInitialToken(AcquireInitialTokenRequest.create("test")).token(); | ||
|
|
||
| AwsErrorDetails errorDetails = AwsErrorDetails.builder() | ||
| .errorCode("IDPCommunicationError") | ||
| .build(); | ||
|
|
||
| IdpCommunicationErrorException failure = IdpCommunicationErrorException.builder() | ||
| .awsErrorDetails(errorDetails) | ||
| .build(); | ||
| RefreshRetryTokenRequest refresh = RefreshRetryTokenRequest.builder() | ||
| .token(token) | ||
| .failure(failure) | ||
| .build(); | ||
| assertThat(strategy.refreshRetryToken(refresh).delay()).isGreaterThan(Duration.ZERO); | ||
| } | ||
|
|
||
| private static Stream<Arguments> retryModeResolutionCases() { | ||
| return Stream.of( | ||
| Arguments.of("standard", StandardRetryStrategy.class), | ||
| Arguments.of("legacy", LegacyRetryStrategy.class), | ||
| Arguments.of("adaptive", AdaptiveRetryStrategy.class) | ||
| ); | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Should we add
<scope>test</scope>here as well? Looks like its only used in testThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes!