Fix long overflow in CachedSupplier.maxStaleFailureJitter() that permanently disables credential refresh after 58 consecutive failures#6806
Open
vinubhagavath-dev wants to merge 1 commit intoaws:masterfrom
Conversation
When numFailures reaches 58, (1L << 57) * 100 overflows signed long, producing a negative duration that bypasses the 10-second cap in ComparableUtils.minimum(). This permanently sets the cached value's stale time to millions of years in the future, preventing any further credential refresh for the lifetime of the process. Clamp overflowed values to Long.MAX_VALUE so the 10-second cap is always respected.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
CachedSupplier.maxStaleFailureJitter() has a long overflow that permanently disables credential refresh after 58 consecutive failures.
When numFailures reaches 58, (1L << 57) * 100 overflows signed long, wrapping to a negative value.
ComparableUtils.minimum(negativeDuration, 10s) returns the negative duration (since it's "less than" 10s), which flows into
jitterTime() and produces a stale time millions of years in the future. The SDK never attempts to refresh credentials again.
Observed in production
During the recent outage, InstanceProfileCredentialsProvider with StaleValueBehavior.ALLOW hit 58 consecutive failures:
(consecutive failures: 57) Cached value expiration has been extended to 2026-03-18T04:45:56Z
(consecutive failures: 58) Cached value expiration has been extended to +75191085-06-13T12:51:54Z
Entire application restart was required to restore credential refresh.
Fix
Clamp overflowed negative values to Long.MAX_VALUE, ensuring ComparableUtils.minimum() always caps at 10 seconds as intended.
Testing
Verified that for numFailures values 1 through 100, maxStaleFailureJitter() always returns a positive duration ≤ 10 seconds.