Repository navigation
Give the per-user refresh worker one owner - #7354
Merged
jhrozek merged 1 commit intoNov 27, 2026
Merged
Conversation
The per-user refresh worker ran without a deadline, so a hung row resolution inside the refresher, or the worker's own suppression lookups, could keep the goroutine alive indefinitely. It now runs under its own one-minute deadline, longer than the refresher's refresh timeout, which still bounds the provider call. Who recorded a refresh outcome was decided by two independent checks of ctx.Err(), one in the worker after sending and one in the caller. They raced: a caller that saw the failure and was then cancelled produced a second WARN, and a worker that saw ctx live while the caller then saw it cancelled left the backoff unrecorded. The caller's select now decides: if it receives the result it records it; if ctx ends first it marks the work abandoned and the worker records it. The read returns an internal sentinel for that case, still matching ErrRefreshFailed and ctx.Err(). Whether a refresh was ID-token-only was re-derived from the row's ExpiresAt at failure time, which misread a storage ErrExpired row with no expiry as ID-token-only and dropped failures whose access token expired during the wait. The call site now passes it explicitly. An ID-token-only refresh no longer returns the stored credential when its access token expired during the refresh, whether or not the caller was still waiting; the read returns the refresh error instead. The docs no longer tell callers to log a failure category rather than error text, which neither the service nor its caller did, and describe which background failures are logged and backed off. Co-authored-by: Mecatl <[email protected]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7354 +/- ##
=======================================
Coverage 82.59% 82.60%
=======================================
Files 943 943
Lines 96943 96952 +9
=======================================
+ Hits 80074 80089 +15
+ Misses 16864 16858 -6
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
rdimitrov
approved these changes
Nov 27, 2026
rdimitrov
left a comment
Member
There was a problem hiding this comment.
Reviewed against #7351.
- Ownership handoff: sound.
doneis unbuffered, and on every path the caller either receives the result or closesabandoned. So exactly one side records the outcome and the worker never blocks, including when the result andctx.Done()are ready at the same moment. idTokenOnly: passing it explicitly fixes the zero-expiryErrExpiredrow.- Expiry check in
refreshForIDToken: it runs before both the caller-left return and the stored-credential fallback. No expired access token is handed out, on the per-user path or the session paths. - Session-mode callers: they change only in the case the PR describes. A provider whose access token expired during a failed ID-token refresh now goes to the failed map and gets a 401, which is what a failed refresh of an expired access token already did.
- Worker deadline: it doesn't cut a save short.
RefreshAndStoreruns the provider call and the store under its ownWithoutCancelwith a 30s timeout.
go test -race passes on ./pkg/auth/upstreamtoken/... and ./pkg/authserver/..., and the upstreamtoken package also passes five repeated runs.
3 of 4 tasks
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
A review of the delegated credential work found problems in the per-user refresh worker that "Bound per-user upstream token reads by context" (#7351) introduced. The worker had no deadline of its own. Who records a failed refresh was decided by two racing
ctx.Err()checks, which could log a failure twice or not back it off at all. And an access token that expired while its ID token was being refreshed could be handed out.selectdecides: if it got the result, it records it; if its context ended first, it marks the work abandoned and the worker records it. The read still returns an error matching bothErrRefreshFailedand the context error.ExpiresAt, which misread a storageErrExpiredrow with no expiry, and silently dropped failures whose access token expired during the wait.docs/arch/11-auth-server-storage.md) no longer tell callers to log a failure category instead of the error text, which neither the service nor its only caller did. They also describe which background failures are logged and backed off.Type of change
Test plan
task test)task lint-fix)Ran
go test -raceover./pkg/auth/upstreamtoken/...and./pkg/authserver/.... New synctest tests cover the worker deadline with a hung refresher, abandoned-refresh recording (exactly one WARN, backoff applied), a zero-expiryErrExpiredrow failing after the caller left, and the access token expiring during an ID-token refresh with the caller waiting and with the caller gone. The deadline, ID-token-only and expiry tests were each checked to fail with their fix removed.Does this introduce a user-facing change?
For embedders reading through
InProcessService: before, if an ID-token-only refresh failed and the access token had expired during that refresh,GetValidTokensForUser,GetValidTokensandGetAllUpstreamCredentialsreturned the stored, now-expired credential with no error. Now they return the refresh error, as they do for a failed access-token refresh. A failed background refresh after the caller left is logged once at WARN instead of possibly twice.Special notes for reviewers
callerLeftRefreshdoc explains why the decision uses the abandoned signal and notctx.Err().