fix(flyteidl): auth interceptor CondWait deadlock on failed token refresh - #7946
Merged
SVilgelm merged 1 commit intoAug 31, 2026
Conversation
…resh Broadcast on every exit of the refresh critical section and bound CondWait so a missed or raced broadcast cannot park callers forever. Signed-off-by: Sergey Vilgelm <sergey@union.ai>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7946 +/- ##
==========================================
+ Coverage 57.25% 57.27% +0.02%
==========================================
Files 931 931
Lines 58308 58311 +3
==========================================
+ Hits 33383 33399 +16
+ Misses 21866 21853 -13
Partials 3059 3059
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
wild-endeavor
approved these changes
Aug 31, 2026
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.
Why are the changes needed?
The auth interceptor's token-refresh path can permanently deadlock a caller. In
NewAuthInterceptor, when a request fails with an authentication error:Two defects combine:
TryLockwinner broadcasts only on success. IfMaterializeCredentials(or the cache purge) fails — e.g. the auth server is briefly unreachable — it returns without waking waiters.TokenCacheInMemoryProvider.CondWaitis a baresync.Cond.Waitover a no-op locker: no timeout, and no check-then-wait mutual exclusion, so a broadcast that fires just before the wait is lost (sync.Condhas no memory).A waiter parked in
CondWaitthen sleeps until the next successful refresh — which on a low-traffic client may never come. We hit this in production: a goroutine was blocked inCondWaitfor 9+ hours (confirmed by goroutine dump), hanging its caller indefinitely. The RPC deadline cannot help because the wait happens inside the interceptor, outside context control.What changes were proposed in this pull request?
auth_interceptor.go: broadcast is now deferred by theTryLockwinner, so every exit path (including refresh failure) wakes waiters.cache/token_cache_inmemory.go:CondWait/CondBroadcastnow use a close-and-replace notification channel (atomic.Pointer+Swap, so concurrent broadcasters never double-close) with a 30s bound on the wait. A missed or raced broadcast degrades to a short delay followed by the caller's normal retry instead of an unbounded hang.No interface changes;
NoopLockeris kept (still used by flytectl's keyring token cache).How was this patch tested?
token_cache_inmemory_test.go: broadcast wakes all waiters; wait times out when no broadcast comes; wait after a missed (pre-wait) broadcast returns; concurrent broadcasts don't panic. Passes with-race.CondBroadcastis called on the error path.Labels
fixed
Setup process
Screenshots
Check all the applicable boxes
Related PRs
unionai/flyte#1009 (same fix in Union's fork, where the production incident occurred)
Docs link