Repository navigation
Conversation
On Cloudflare Workers, a promise created by one request can't settle in another. If the request that started a deduped refresh ends early, every waiter rejects and the map entry is never removed, so later requests with that refresh token fail until the user signs in again. Waiters now drop the dead entry on any non-TokenRefreshError rejection and refresh in their own request. Fixes #73
Contributor
[Medium impact] The PR appears safe to merge; no actionable issues were found. Summary
nicknisi explicitly acknowledged that recovery requires a new sign-in if the abandoned request already consumed the refresh token.
|
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.
Fixes #73.
On Cloudflare Workers, a promise created by one request can't settle in another.
refreshTokens()shares in-flight refreshes across requests through a map on the singletonAuthKitCore. If the request that started a refresh ends early (for example, the client navigates away), every request waiting on it rejects with the Workers cross-request error. The.then(cleanup, cleanup)also never runs, so the dead promise stays in the map. Every later request with that refresh token then gets a 500 until the user signs in again.Fix: a waiting request that gets anything other than a
TokenRefreshErrorfrom a shared refresh removes the map entry (only if it still points to the dead promise) and refreshes in its own request. Real refresh failures still reach every waiter, and the dedupe from #33 still covers the normal case.If the dead request's WorkOS call had already used up the refresh token, the retry fails with a normal
TokenRefreshErrorand the user has to sign in again. That's expected.Testing
AuthKitCoreper isolate. Before the fix, the concurrent request and every later request failed with the error from the issue. After the fix, both succeed.pnpm test,typecheck,lintandformat:checkall pass.