Repository navigation
Conversation
SteffenDE
force-pushed
the
sd-resumable-websocket
branch
from
November 30, 2026 16:36
3d62936 to
9bdc3ca
Compare
SteffenDE
force-pushed
the
sd-resumable-websocket
branch
2 times, most recently
from
December 2, 2026 17:32
726bf0a to
e97f8bf
Compare
Only connect/3 checks a socket, when the client connects. Long polling keeps the socket when a request fails, and the client resumes it with its next poll, which phoenix.js marks with phx:resume. The session now passes the params and connect_info of that poll to the new optional Phoenix.Socket.resume/3 callback, for example to verify that the user is still logged in. Returning :error stops the socket, so the client connects again. Custom transports can implement the new optional Phoenix.Socket.Transport.handle_resume/2 callback. The poll that resumes answers right away when the session has no messages, as the client waits for it before it reports that it recovered. The session answers requests in order and only answers a flush when it has messages, so its echo of a request sent after the flush tells that it has none. A client that resumes also sends the private topic of its token. A session rejects a topic that is not its own, as another session can get the pid of a session that stopped, and keeps running for its own client. LongPoll now reads the params and auth token of the socket again for a poll that resumes, so the socket checks its current credentials.
With the new :resumable WebSocket option, clients that opt in with the resumable: true option of the phoenix.js Socket resume their socket over a new WebSocket after the connection failed, without rejoining channels. :resumable can also be an MFA that decides for each new connection. The socket runs in a Phoenix.Transports.Session, like a long-poll socket. The WebSocket process attaches to it as a pipe. Both sides number their messages, keep them until the other side confirmed them, and send the missed ones again after resuming. The client resumes with the token of the session and the number of the last message it received, which invokes Phoenix.Socket.resume/3. Heartbeats, their replies, and ping and pong frames belong to the current WebSocket, so neither side numbers or replays them. The new ResumableWebSocket transport resumes the session with backoff, reports interruptions with onSuspend and onResume, and resumes instead of reconnecting when the heartbeat times out. When the session is gone, or the server does not keep the socket, it closes so that the socket connects again. A session continues with the transport that started it. Long-poll requests only prove that the client has the token, so a session that a WebSocket started rejects them with 410, and a WebSocket cannot resume a long-poll session. The session keeps running for its own client. Parts of this come from #6887 and #6905.
SteffenDE
force-pushed
the
sd-resumable-websocket
branch
from
December 2, 2026 17:51
e97f8bf to
5ed4530
Compare
Only nodes before Phoenix v1.8.18 and 1.8.18 nodes serving older clients send unnumbered requests. Older clients have no WebSocket session token, so the session stops for such a request like for any other.
This branch has not been 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.
Part 4(a) of #6885 (comment).