Skip to content

Stop retrying a failed token refresh on every request#199

Merged
ericmj merged 1 commit into
mainfrom
clear-oauth-token-on-refresh-failure
Jun 17, 2026
Merged

Stop retrying a failed token refresh on every request#199
ericmj merged 1 commit into
mainfrom
clear-oauth-token-on-refresh-failure

Conversation

@ericmj

@ericmj ericmj commented Jun 17, 2026

Copy link
Copy Markdown
Member

When a global OAuth token is expired and its refresh is rejected by the server, the refresh was re-attempted on the next request: a failed refresh changed no state, so each caller serialized behind the token-refresh lock re-read the same expired token and re-POSTed to /oauth/token. Resolving over N packages produced N failed refreshes.

Add an optional clear_oauth_tokens callback. On a failed refresh, do_resolve_oauth_token_with_context invokes it while holding the token-refresh lock so the build tool can invalidate the unusable token; callers behind the lock then re-read it as absent and fall back to unauthenticated instead of retrying. The refresh is attempted at most once per run. The callback is optional, so existing callers keep working unchanged.

When a global OAuth token is expired and its refresh is rejected by the server, the refresh was re-attempted on the next request: a failed refresh changed no state, so each caller serialized behind the token-refresh lock re-read the same expired token and re-POSTed to /oauth/token. Resolving over N packages produced N failed refreshes.

Add an optional clear_oauth_tokens callback. On a failed refresh, do_resolve_oauth_token_with_context invokes it while holding the token-refresh lock so the build tool can invalidate the unusable token; callers behind the lock then re-read it as absent and fall back to unauthenticated instead of retrying. The refresh is attempted at most once per run. The callback is optional, so existing callers keep working unchanged.
@ericmj ericmj requested a review from maennchen June 17, 2026 15:01
@ericmj ericmj merged commit 19001bb into main Jun 17, 2026
10 checks passed
@ericmj ericmj deleted the clear-oauth-token-on-refresh-failure branch June 17, 2026 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants