Skip to content

fix(core): don't retry on InvalidGrantException because it is terminal #5764

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
merged 3 commits into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import software.amazon.awssdk.regions.Region
import software.amazon.awssdk.services.ssooidc.SsoOidcClient
import software.amazon.awssdk.services.ssooidc.SsoOidcTokenProvider
import software.amazon.awssdk.services.ssooidc.internal.OnDiskTokenManager
import software.amazon.awssdk.services.ssooidc.model.InvalidGrantException
import software.amazon.awssdk.services.ssooidc.model.SsoOidcException
import software.amazon.awssdk.utils.SdkAutoCloseable
import software.amazon.awssdk.utils.cache.CachedSupplier
Expand Down Expand Up @@ -252,13 +251,6 @@ internal val DEFAULT_PREFETCH_DURATION = Duration.ofMinutes(20)
val ssoOidcClientConfigurationBuilder: (ClientOverrideConfiguration.Builder) -> ClientOverrideConfiguration.Builder = { configuration ->
configuration.nullDefaultProfileFile()

// Add InvalidGrantException to the RetryOnExceptionsCondition
configuration.retryStrategy { strategy ->
strategy.retryOnException {
it is InvalidGrantException
}
}

configuration.addExecutionInterceptor(object : ExecutionInterceptor {
override fun modifyException(context: Context.FailedExecution, executionAttributes: ExecutionAttributes): Throwable {
val exception = context.exception()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,14 @@ class InteractiveBearerTokenProviderTest {
}

@Test
fun `oidcClient retries twice on InvalidGrantException failure`() {
fun `oidcClient does not retry on InvalidGrantException failure`() {
fun verifyRetryAttempts(configuration: ClientOverrideConfiguration.Builder) {
configuration.addExecutionInterceptor(
object : ExecutionInterceptor {
override fun onExecutionFailure(context: Context.FailedExecution?, executionAttributes: ExecutionAttributes?) {
super.onExecutionFailure(context, executionAttributes)

// 3 total network calls, showing 4 since the sdk increments the attempt count at the beginning
// of the loop before it checks whether it's allowed to retry.
assertThat(executionAttributes?.getAttribute(InternalCoreExecutionAttribute.EXECUTION_ATTEMPT)).isEqualTo(4)
assertThat(executionAttributes?.getAttribute(InternalCoreExecutionAttribute.EXECUTION_ATTEMPT)).isEqualTo(1)
}
}
)
Expand Down
Loading