Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1966b8d
Make LongPoll sessions resumable by default
SteffenDE Oct 28, 2026
673a377
Number long-poll messages and check resumed sessions
SteffenDE Oct 29, 2026
8de4a91
Resume WebSocket sockets over a new connection
SteffenDE Oct 29, 2026
dfbcbbf
Continue resumable sockets across transports
SteffenDE Oct 29, 2026
436aab9
Explain why polls continue when a resume check is slow
SteffenDE Oct 29, 2026
ea2c943
Name the close codes of resumable sessions
SteffenDE Oct 29, 2026
1d0dc95
Remove the empty terminate/2 of the WebSocket pipe
SteffenDE Oct 29, 2026
1f46644
Mark the tests of Phoenix 1.8 compatibility for removal in 1.10
SteffenDE Oct 29, 2026
8fb8363
Verify that resume tokens belong to their session
SteffenDE Oct 29, 2026
a0a235d
keep callback pushes buffered after the messages we already kept
SteffenDE Oct 30, 2026
d49ce01
allow an mfa in resumable
SteffenDE Nov 6, 2026
d3c95cd
Fix connection state before reporting long-poll fallback errors
SteffenDE Nov 6, 2026
c774cad
Namespace resumable transport query parameters
SteffenDE Nov 6, 2026
1032acb
Notify socket recovery after replaying buffered messages
SteffenDE Nov 6, 2026
a2be5ac
Require a resume to long poll a WebSocket session
SteffenDE Nov 6, 2026
7de89b8
Close resumable sessions normally when the socket is disconnected
SteffenDE Nov 6, 2026
6ad1a6c
Use the window of the transport a session continues with
SteffenDE Nov 6, 2026
408b3ed
Answer the poll that resumes without waiting for messages
SteffenDE Nov 6, 2026
153d5bd
Give resume attempts over a WebSocket their own timeout
SteffenDE Nov 6, 2026
2fb44b1
Don't drop messages flushed after the listen window for legacy clients
SteffenDE Nov 6, 2026
eeeb0fb
resumeAfterMs option
SteffenDE Nov 9, 2026
772253c
clarify
SteffenDE Nov 9, 2026
aaf4726
try to unify pipe and poll handling
SteffenDE Nov 9, 2026
51c440d
rename
SteffenDE Nov 9, 2026
ae70ae5
re-read connection info on resume
SteffenDE Nov 9, 2026
91b2e0c
handle websocket control frames
SteffenDE Nov 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@

## Enhancements

* [phoenix.js] Long polling retries interrupted requests without rejoining
channels while its server session remains alive. Messages are retained until
acknowledged and retried pushes are deduplicated. New `socket.onSuspend` and
`socket.onResume` callbacks report interruptions and recovery without a
channel error. Older servers retain the existing reconnect behavior. During
a rolling deploy, a session that reaches a node with an older server falls
back to that behavior for the rest of the session.
* [Phoenix.Endpoint] Add the `:resumable` WebSocket option. Clients that use the
`resumable: true` option of the `phoenix.js` Socket resume the socket over a new
WebSocket after the connection failed or the heartbeat timed out, without
rejoining channels. Both sides send the messages the other side missed. With
`longPollFallbackMs`, clients continue the socket with long polling when they
cannot resume it over a WebSocket in time. Clients connecting to servers without
the option behave like before. Pass an MFA tuple instead of `true` to decide for
each connection, for example to only let signed-in users resume
* [Phoenix.Socket] Add the optional `c:Phoenix.Socket.resume/3` callback to check
a client that resumes its session after a failed request or WebSocket, 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
`c:Phoenix.Socket.Transport.handle_resume/2` callback
* The longpoll session token is now sent in a `x-phoenix-longpoll-token`
header instead of the query string. If you do rolling deploys where both
old and new nodes are active at the same time, ensure that you deploy
Expand Down
3 changes: 3 additions & 0 deletions assets/js/phoenix/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ export default class Connection {
this.channelsErrored = false
// set once the close event was handled, as LongPoll can emit it more than once
this.closeHandled = false
this.suspended = false
transport.onopen = () => { if(this.isCurrent()){ socket.onConnOpen() } }
transport.onerror = error => { if(this.isCurrent()){ socket.onConnError(error) } }
transport.onmessage = event => { if(this.isCurrent()){ socket.onConnMessage(event) } }
transport.onsuspend = () => { if(this.isCurrent()){ socket.onConnSuspend(this) } }
transport.onresume = () => { if(this.isCurrent()){ socket.onConnResume(this) } }
transport.onclose = event => {
if(this.isCurrent() && !this.closeHandled){
this.closeHandled = true
Expand Down
3 changes: 3 additions & 0 deletions assets/js/phoenix/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ export const DEFAULT_VSN = "2.0.0"
export const SOCKET_STATES = {connecting: 0, open: 1, closing: 2, closed: 3}
export const MAX_LONGPOLL_BATCH_SIZE = 100;
export const DEFAULT_TIMEOUT = 10000
export const DEFAULT_RESUME_AFTER_MS = (tries) => [100, 500, 1000, 2000][tries - 1] || 5000
export const WS_CLOSE_NORMAL = 1000
// the close code of a transport whose session is gone, so the socket connects again
export const CLOSE_SESSION_GONE = 3410
export const CHANNEL_STATES = {
closed: "closed",
errored: "errored",
Expand Down
28 changes: 28 additions & 0 deletions assets/js/phoenix/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,32 @@
* socket.onClose( () => console.log("the connection dropped") )
* ```
*
* LongPoll automatically retries interrupted requests while the server keeps
* its session alive. During recovery, channels stay joined and outgoing messages
* are buffered. Use `onSuspend` and `onResume` to show connection status without
* resetting channel state:
*
* ```
* socket.onSuspend( () => console.log("recovering the connection") )
* socket.onResume( () => console.log("the connection recovered") )
* ```
*
* `onResume` runs after delivering the incoming messages buffered at resumption,
* so callbacks see those updates. It does not wait for replies to outgoing pushes.
*
* Longpoll sessions are resumable by default, WebSockets resume with the `resumable`
* option, which also requires the `:resumable` WebSocket option in your server's endpoint:
*
* ```
* let socket = new Socket("/socket", {resumable: true})
* ```
*
* ```elixir
* socket "/ws", UserSocket,
* websocket: [resumable: true, ...],
* longpoll: [...]
* ```
*
*
* ## Channel Hooks
*
Expand Down Expand Up @@ -195,13 +221,15 @@
import Channel from "./channel"
import LongPoll from "./longpoll"
import Presence from "./presence"
import ResumableWebSocket from "./resumable_websocket"
import Serializer from "./serializer"
import Socket from "./socket"

export {
Channel,
LongPoll,
Presence,
ResumableWebSocket,
Serializer,
Socket
}
Loading
Loading