-
Notifications
You must be signed in to change notification settings - Fork 719
fix(realtime): refresh the access token before reconnecting, not only when a refresh is already in flight #2614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fufu830118
wants to merge
1
commit into
supabase:master
Choose a base branch
from
fufu830118:fix/refresh-token-before-reconnect
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π― Functional Correctness | π Major | β‘ Quick win
Prevent
connect()from starting a second auth refresh.setAuth()clears_authPromisein itsfinallyblock before it resolves. Therefore,connect()at Line 888 enters the existingaccessToken && !this._authPromisebranch at Lines 303-308 and callssetAuth()again. The supplied regression test expects one callback call after reconnect; this path makes two calls. With that test fixture, the second call readstokens[2]and can overwriteaccessTokenValuewithundefined. Use a reconnect connection path that skips the initial auth bootstrap after this refresh, or carry an explicit βauth already refreshedβ guard intoconnect().π€ Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the catch β the extra
setAuth()call is real, and it is the one flagged as open question #2 in the PR description. Measured against the published packages: 2 β 3accessToken()invocations per reconnect (5-authcalls.mjsin the linked repro).Two clarifications on the rest of the finding:
1. The falsy-overwrite is pre-existing, and the join payload is guarded.
In
_performAuth,this.accessTokenValue = tokenToSendis unconditional, so a callback returningundefineddoes clobber the cached value β but that is true onmastertoday, independent of this PR. This PR only adds one more opportunity to reach it. What actually goes out on the wire is protected: the same block doestokenToSend && channel.updateJoinPayload(payload), so a falsy return degrades the cache, not the join frame.2. There is no regression test in this PR.
It changes exactly one file β
packages/core/realtime-js/src/RealtimeClient.ts, +15/β0. The runnable tests live in a separate repo linked from #2613 (6 Node tests, ~2 s, no Supabase project), and none of them index a fixture array past its end. So thetokens[2]scenario does not exist here.On de-duplicating the call: it needs a short-circuit inside
connect(), which I deliberately left untouched to keep the diff to the one function. Happy to add it here if you would prefer that shape β or to drop this PR entirely if you would rather solve the whole thing on the phoenix side (supabase/phoenix#51), since that path is where the token never gets refreshed at all.