feat: Fix ClientSideCredentialAccessBoundary race condition when multiple concurrent calls are made to generateToken.#1911
Closed
vverman wants to merge 1 commit intogoogleapis:mainfrom
Closed
Conversation
…iple concurrent calls are made to generateToken.
Member
|
@vverman Thanks for raising this PR! We've begun the monorepo migration effort over to google-cloud-java. Can you raise this PR in that repo? For the existing PRs open, I will manually migrate them over when there are merged. New PRs should be raised in the monorepo. |
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.
Fixes googleapis/google-cloud-java#12571
In the previous implementation, when multiple threads concurrently called generateToken() on a newly created factory instance, they would find an existing refresh task in progress and wait for its completion.
However, they were waiting on the inner network task to finish, rather than waiting for the factory's state update to complete. This created a window where a waiting thread could wake up and proceed to read the factory state (like intermediateCredentials) before the asynchronous listener had a chance to populate it, resulting in a NullPointerException.
We resolved this by merging the state update and the completion signal into a single, serialized listener and making waiting threads wait on this unified completion signal. This ensures that any thread waking up is guaranteed to see the fully initialized state.