fix: clear async workload refresh state after sync failures - #877
Open
sylvesterkaczmarek wants to merge 2 commits into
Open
fix: clear async workload refresh state after sync failures#877sylvesterkaczmarek wants to merge 2 commits into
sylvesterkaczmarek wants to merge 2 commits into
Conversation
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.
Summary
Ensure
WorkloadIdentityAuth.getTokenAsync()clears its shared refresh state when a customSubjectTokenProvider.getTokenAsync()throws synchronously instead of returning a future.Fixes #852.
Problem
getTokenAsync()stores a newrefreshInFlightfuture before it calls the provider. IfgetTokenAsync()on the provider throws synchronously, the exception escapes before anywhenCompletecallback is registered.That leaves
refreshInFlightpointing at a future that will never complete.For a foreground refresh, the first caller sees the synchronous exception and every later caller waits on the abandoned shared future indefinitely. The same state leak can occur when an expiring cached token triggers a background refresh.
Fix
Centralize async refresh startup in
startAsyncRefresh().The helper:
refreshTokenAsync()inside atryblock;finishRefresh()path sorefreshInFlightis cleared and waiters are completed;CompletableFutureto the foreground caller instead of throwing before a future is returned;Asynchronous provider and token-exchange failures continue through the existing completion callback unchanged.
Regression coverage
Added focused tests for both affected paths:
getTokenAsync()call to return a failed future, and a second call starts a new refresh instead of hanging on stale state.Validation
mainat6a46d024ed67e2be889a4c729837a664d5e7902c;WorkloadIdentityAuth.kt;Full repository validation is left to GitHub Actions because this environment does not have a complete local checkout/toolchain for the repository.
Risk
Low. Normal successful refreshes and asynchronously completed failures keep their existing flow. The behavior changes only when refresh startup itself throws before returning a
CompletableFuture.