Skip to content

feat: Fix ClientSideCredentialAccessBoundary race condition when multiple concurrent calls are made to generateToken.#1911

Closed
vverman wants to merge 1 commit intogoogleapis:mainfrom
vverman:fix-clientside-cab-race-condition
Closed

feat: Fix ClientSideCredentialAccessBoundary race condition when multiple concurrent calls are made to generateToken.#1911
vverman wants to merge 1 commit intogoogleapis:mainfrom
vverman:fix-clientside-cab-race-condition

Conversation

@vverman
Copy link
Copy Markdown
Contributor

@vverman vverman commented Apr 1, 2026

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.

…iple concurrent calls are made to generateToken.
@vverman vverman requested review from a team as code owners April 1, 2026 00:57
@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Apr 1, 2026
@vverman vverman requested review from lqiu96 and nbayati April 1, 2026 00:57
@lqiu96
Copy link
Copy Markdown
Member

lqiu96 commented Apr 1, 2026

@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.

@lqiu96 lqiu96 closed this Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[google-auth-library-java] Race condition in ClientSideCredentialAccessBoundaryFactory during concurrent initialization

2 participants