Skip to content

fix: cover concurrent refreshes across adapter instances - #46

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

Bccorb merged 1 commit into
mainfrom
fix/concurrent-refresh-across-instances

Conversation

@Bccorb

@Bccorb Bccorb commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Closes #43

Part of the M14 security work (fells-code/seamless-auth-api#603). The API adds a 5 second refresh replay window in fells-code/seamless-auth-api#613, so two adapter instances presenting the same refresh token each get a 200 with the same successor.

Trace of src/refresh.rs

  • Sharing and the 5 second completed cache are per process. Two instances each call the API, each gets the same refreshToken, sessionId and claims, and each writes the same refresh cookie and an access cookie for the same session. Nothing assumes one winner, so no code change and no shared lock.
  • Only a 200 with a session is kept. Any 401, including refresh_token_reused, is returned as rejected, clears the access and refresh cookies, is never kept and is never retried. The kept window (5s) is within the API window.

Changes

  • Tests: two separate adapters refreshing in parallel against a mock API that follows the replay contract, both 200 with the same refresh cookie and session; refresh_token_reused clears cookies on both the silent refresh and POST /refresh with exactly one upstream call each.
  • README: multi-instance deployment, what the API window covers, no shared lock needed while request spread and clock skew stay under the window, requires the API release that ships #613.

Checks

cargo fmt --check, cargo clippy --all-targets -- -D warnings (default, --no-default-features, --no-default-features --features native-tls) and cargo test (154 + 1 passed) are clean. scripts/check-manifest.sh reports drift on main as well (stale bundled manifest); it is unrelated and left alone.

Add tests for two instances refreshing one token against an API with the
replay window, and for refresh_token_reused staying terminal. Document
multi-instance deployment.
@Bccorb
Bccorb force-pushed the fix/concurrent-refresh-across-instances branch from 7db10bc to 082f1b5 Compare November 19, 2026 16:42
@Bccorb
Bccorb merged commit 5353349 into main Nov 20, 2026
4 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 20, 2026
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(refresh): handle concurrent refreshes across instances

1 participant