-
Notifications
You must be signed in to change notification settings - Fork 974
Fix race conditions in aggregate ProfileFileSupplier #6665
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
Conversation
core/profiles/src/main/java/software/amazon/awssdk/profiles/ProfileFileSupplier.java
Outdated
Show resolved
Hide resolved
| if (state.compareAndSet(currentState, nextState)) { | ||
| return nextAggregate; | ||
| } | ||
| // else: another thread has modified the state in between, retry with the fresh state |
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.
Trying to reason about this. If the state got updated in between, do we actually need to retry here? Assuming that earlier update is also valid.
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.
I think its actually a reasonable assumption to just return whatever the updated state is in this case - which lets us remove the while(true) which is good.
I'm working on benchmarking for this + another optimization that removes the new map creation in most cases.
...les/src/main/java/software/amazon/awssdk/profiles/internal/AggregateProfileFileSupplier.java
Outdated
Show resolved
Hide resolved
|
|
This pull request has been closed and the conversation has been locked. Comments on closed PRs are hard for our team to see. If you need more assistance, please open a new issue that references this one. |



Fix race conditions in aggregate ProfileFileSupplier.
Motivation and Context
This change fixes multiple race conditions in the aggregate ProfileFileSupplier. #6632 re-introduced profile file reloading which exposed these issues, resulting in credentials resolution failure if a shared DefaultCredentialsProvider instance with a profile name configured is used across multiple threads.
The most series issues is that
get()determines whether to recompute the aggregate based on a snapshot ofcurrentValuesBySupplier, butrefreshCurrentAggregate()then reads a different snapshot of that same map — and nothing prevents another thread from mutating it in between. The AtomicReference and synchronizedMap give us local thread safety, but not atomicity across the whole operation.Modifications
Testing
Added a new unit test + manual testing.
Screenshots (if appropriate)
Types of changes
Checklist
mvn installsucceedsscripts/new-changescript and following the instructions. Commit the new file created by the script in.changes/next-releasewith your changes.License