Skip to content

fix(core): cover concurrent refresh across adapter instances and document it - #290

Merged
Bccorb merged 1 commit into
mainfrom
fix/concurrent-refresh-replay
Nov 20, 2026
Merged

Bccorb merged 1 commit into
mainfrom
fix/concurrent-refresh-replay

Conversation

@Bccorb

@Bccorb Bccorb commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Closes #285

The auth API is adding a refresh replay window in fells-code/seamless-auth-api#613. Concurrent refreshes of the same refresh token inside the window each get 200 with the same successor refresh token and session id, so two adapter instances racing one cookie no longer trip reuse detection.

Trace

  • refreshCookieSession and ensureCookies hold per-process state only (in-flight dedupe and the 5 second completed-cookie cache). Nothing assumes one winner across instances, so each instance calls the API and sets the same successor refresh cookie value and an access cookie with the same sid.
  • Any 401 from /refresh, including refresh_token_reused, becomes rejected, which clears the access, registration and refresh cookies. Rejections are never cached and never retried.
  • No code change was needed and no shared lock is added.

Changes

  • Test: two separate module instances refresh concurrently against a mock API that follows the contract; both succeed with the same refresh cookie and sid, and the access tokens differ.
  • Test: refresh_token_reused clears cookies with a single upstream call.
  • README: new Running Multiple Instances section (window, no shared lock needed while spread and clock skew stay under it, requires the API release that ships #613).
  • Patch changeset for @seamless-auth/core.

Checks

pnpm build and pnpm test pass (core 771, express 561, nextjs 692, fastify 578 tests). The repo defines no lint or format scripts.

@Bccorb
Bccorb merged commit f24a5a1 into main Nov 20, 2026
6 checks passed
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.

fix(core): handle concurrent refreshes across instances

1 participant