Skip to content

fix(auth): stop refresh-token rotation race from logging users out#12

Merged
coopbri merged 1 commit into
masterfrom
fix/auth-refresh-rotation-race
Jul 8, 2026
Merged

fix(auth): stop refresh-token rotation race from logging users out#12
coopbri merged 1 commit into
masterfrom
fix/auth-refresh-rotation-race

Conversation

@coopbri

@coopbri coopbri commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Fleet-wide forced re-login was a concurrent refresh-token-rotation race. On app re-open, an SSR page fires many parallel requests carrying the same session cookie; each independently refreshed the single-use OAuth token, all but the winner presented a just-rotated token, and getAuth force-signed-out the still-valid session on the first invalid_grant/FAILED_TO_GET_ACCESS_TOKEN. Confirmed in production logs (logouts arriving in bursts of ~6 within <1s).

Changes

  • Single-flight the token refresh per session so a request burst triggers one rotation instead of N.
  • Degrade, don't destroy: a refresh failure no longer signs the user out. It serves the session without a fresh access token and lets the app's natural 401 -> re-auth path recover a genuinely dead session.

Testing

  • New specs for single-flight and degrade-on-race (red -> green)
  • Full suite: 281 pass; typecheck + lint clean

Pairs with the Gatekeeper rotation reuse grace window (defense in depth at the IDP).

Concurrent SSR requests for one session each refreshed the single-use
OAuth token independently; all but the winner presented a just-rotated
token, and getAuth force-signed-out the still-valid session on the first
failure, logging users out in bursts on every app re-open.

Single-flight the refresh per session so a page-load burst triggers one
rotation instead of many, and degrade instead of destroy on a refresh
failure: serve the session without a fresh access token and let the
natural 401 -> re-auth path recover a genuinely dead session rather than
punishing a benign rotation race.
@coopbri
coopbri merged commit 5909b95 into master Jul 8, 2026
4 checks passed
@coopbri
coopbri deleted the fix/auth-refresh-rotation-race branch July 8, 2026 23:24
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant