Fix expiration in past warning from ProfileFileRefresher. #6157
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.
Fixes a warning logged from the
CachedSupplier
used by theProfileFileRefresher
that expiration (stale time) is in the past.Motivation and Context
ProfileFileSupplier.defaultSupplier()
andProfileFileSupplier.reloadWhenModified()
always logs a warning message indicating that the expiration/stale time is in the past. This happens every time the value is accessed from the cache, since we compareclock.instant()
calculated at 2 separate instances:ProfileFileRefresher
- https://github.com/aws/aws-sdk-java-v2/blob/master/core/profiles/src/main/java/software/amazon/awssdk/profiles/internal/ProfileFileRefresher.java#L86CachedSupplier
- https://github.com/aws/aws-sdk-java-v2/blob/master/utils/src/main/java/software/amazon/awssdk/utils/cache/CachedSupplier.java#L236Modifications
This change adds a stale time to
now
in theProfileFileRefresher
preventing the warning from being logged - and preventing the CachedSupplier from adding 1 second to the stale time when it detects this case.Does this change any refresh behavior? Does this change when changes in the profile files are reloaded?
No - there should not be behavior changes.
In the current code, the
ProfileFileRefresher
sets a stale time ofnow
, which always triggers theProfileFileRefresher
to detect a past expiration and adds 1 second to the stale time. This happens even when the values ofclock.instant()
are identical because the values are checked using isBefore which checks strictly less than and not equal.This change adds the same 1 second delay to the stale time, but does so explicitly in the
ProfileFileRefresher
.Testing
Modified existing test cases. Note that the test cases were incorrectly assuming that the CachedSupplier would use the jitter path - however, jitter is only applied in prefetch cases and when the
staleValueBehavior
is set toALLOW
- but in theProfileFileRefresher
, prefetch is never done (because prefetch time defaults to Instant.MAX) and staleValueBehavior is alwaysSTRICT
.Types of changes
Checklist
mvn install
succeedsscripts/new-change
script and following the instructions. Commit the new file created by the script in.changes/next-release
with your changes.License