Repository navigation
Host: one shared Neon Realtime client per address for every live read - #4403
Merged
Merged
Conversation
Every liveRows read at one Realtime URL now shares one client and its socket, as Neon's guide prescribes. A client whose subscription moves to error is replaced for the next read and closed once its last read lets go; a sign-out or account switch drops the shared client. Co-authored-by: luke-agent[bot] <339870089+luke-agent[bot]@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
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.
Before this, every
liveRowsread in the host opened its own Realtime client and socket. Neon's guide says to create one client for the whole app, because every subscription shares its connection (subscribing).Supersedes #3287 with the same approach, rebuilt on
main'slive-follow.ts. #3287 doesn't rebase cleanly onto today's tree.shareLiveClientskeeps one client per Realtime URL, handed out as handles. It's loaded once however many reads wait on it. If loading fails it's forgotten, so the next read loads it again. The client closes when its last handle lets go.openRealtimeClientis this shared opener, so every area'sliveRowsuses it without other changes.errorand the client can't reconnect. So when any subscription on the shared client goes toerror, the client is forgotten. The next subscribe or resubscribe opens a new one, and the old one closes once nothing holds it.compose-account.ts's account change) callsdropRealtimeClients(). The next read opens a fresh client.liveRowsare unchanged.A decision: the client is replaced on any
error, not only a connection-level one. The client's connection error codes include whatever the server sends, so they can't be listed reliably. A per-subscription error such as a decode failure therefore costs one extra client, and the old client keeps serving the reads that hold it.Tests (
live-follow.test.ts): two reads share one client and it closes after the last one; a connection error makes the next read open a new client and the old one closes; sign-out (drop) drops the client; a failed load is retried.@luke/hosttests and typecheck pass.Made with Luke