Repository navigation
docs(realtime): add connect, subscribe, reconnect backoff and heartbeat specs - #304
Merged
Merged
Conversation
|
Caution Review failedThe pull request is closed.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
grdsdev
commented
Oct 29, 2026
Tr00d
approved these changes
Oct 29, 2026
spydon
reviewed
Oct 30, 2026
spydon
added a commit
to supabase/supabase-flutter
that referenced
this pull request
Oct 30, 2026
…he SDK spec (#2114) Aligns the Realtime client with the connection recovery specs in supabase/sdk#304, including the fixed heartbeat beat from supabase/sdk#304 (comment). ## Connect (`realtime.client.connect`) - The default reconnect delay is now full jitter with a 1 second base and a 30 second cap: a random duration between zero and `min(30 s, 1 s × 2^(attempt − 1))`. It used to be a delay doubling from 1 to 10 seconds without jitter. - The reconnect attempt count resets when a socket opens, instead of after the access token resolved. A connection that opens and then fails its token resolution therefore reconnects as attempt 1. ## Subscribe (`realtime.channel.subscribe`) - Channel rejoins use their own fixed delays of 1, 2, 5 and then 10 seconds, instead of `reconnectAfter`. - A join rejected with `ChannelRateLimitReached`, `ConnectionRateLimitReached`, `ClientJoinRateLimitReached` or `DatabaseConnectionRateLimitReached` waits 30 seconds before the next rejoin. - A join answered with an error is now retried like a join that timed out. It used to leave the channel errored until the next reconnect. - Rejoins are only scheduled while the socket is open. When a socket opens, every channel's rejoin attempt count resets and errored channels rejoin at once. ## Heartbeat (`realtime.configuration.heartbeat_interval`) - The heartbeat already runs at a fixed beat, as the spec now requires. - A missing reply now treats the socket as dead at once: channels are marked as errored, the socket subscription is dropped so no further messages are dispatched, a reconnect is scheduled, and the sink is closed. The client used to close the sink and wait for it to close, up to `connectionCloseTimeout`, while still dispatching messages. ## Reconnect backoff (`realtime.configuration.reconnect_backoff`) - `reconnectAfter` now only sets the socket reconnect delay. A negative delay already counts as zero, since `Timer` treats it that way. `MIGRATION.md` gets a section on the new defaults and on `reconnectAfter` no longer driving rejoins. New tests in `connection_recovery_test.dart` cover the rejoin steps, the rate limit wait, the reset on open, the missing heartbeat reply and the fixed beat. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Realtime reconnect delays are randomized and can increase up to 30 seconds. * Channel rejoin delays follow a separate schedule: 1, 2, 5, then 10 seconds. Rate-limited joins wait 30 seconds. * Failed channel joins retry when the socket is connected, and channels rejoin after reconnection. * An unanswered heartbeat now closes the socket promptly so reconnection can begin. * **Documentation** * Updated the migration guide to explain reconnect and rejoin delays, rate-limit handling, and heartbeat behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
spydon
added a commit
to supabase/supabase-py
that referenced
this pull request
Nov 3, 2026
**What this changes** Channel rejoin now follows the Realtime `channel/subscribe` spec proposed in supabase/sdk#304. **The problem** The rejoin timer computed its delay as `2**(tries + 1)`, so the first rejoin waited 4 seconds and later ones grew without limit. On top of that: - The rejoin timer callback rescheduled itself every time it fired, so a channel kept resending its join on the backoff interval, even while a join was still waiting for a reply. - A join that the server rejected with an error reply never scheduled a rejoin. - Rate-limit join errors were retried on the normal schedule. - After a reconnect, only channels that were joined or joining got rejoined. Channels that were already errored waited for their timer, and attempt counts were never reset. **The fix** - Rejoin delays are 1, 2, 5 and 10 seconds for attempts 1 to 4, then 10 seconds for every later attempt. - `AsyncTimer` passes the actual attempt number to its delay function, and `schedule_timeout` accepts an explicit delay override. - A join that fails or times out schedules a rejoin, but only while the socket is open. The rejoin timer no longer reschedules itself. - A join rejected with `ChannelRateLimitReached`, `ConnectionRateLimitReached`, `ClientJoinRateLimitReached` or `DatabaseConnectionRateLimitReached` waits 30 seconds before the next rejoin. - When the socket opens, every channel's rejoin attempt count resets, and each errored channel rejoins at once. - `_reconnect` remembers which channels were joined or joining before the socket dropped, and those channels rejoin on the new socket even if a late join reply from the old connection marks them joined during the handshake. Each channel rejoins once, and channels that were removed or are being left are skipped. The socket reconnect curve (`AsyncRealtimeClient.connect`) is unchanged here. **Behavior change** A join rejected for a reason other than rate limiting (for example `Unauthorized`) is now retried on the stepped schedule, matching the spec and phoenix.js. Before, the channel stayed errored after a join error reply. **Test** `tests/test_channel_rejoin.py` covers the stepped schedule, join errors, the rate-limit delay, no rejoin while disconnected, no self-rescheduling, the reset and immediate rejoin on socket open, and rejoining a channel that a stale reply marked joined during a reconnect. Verified with ruff, mypy, and the full realtime suite against local infra. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Improved channel recovery after connection interruptions. Channels retry joining only while connected, avoiding repeated retries during disconnection. * Adjusted retry timing for join timeouts and errors, including a 30-second delay for rate-limited errors and retry intervals capped at 10 seconds. * After reconnecting, eligible channels are rejoined and their retry timers are reset, helping restore channel availability. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>
This was referenced Nov 5, 2026
4 of 5 tasks
grdsdev
added a commit
that referenced
this pull request
Nov 10, 2026
Stacked on #304. Merge #304 first; this PR then retargets to `main`. Adds a "Server channel error" section to `specs/realtime/channel/subscribe.md`: - A `phx_error` for a stale `join_ref` changes nothing. - On a joined channel, the client reports the error, marks the channel errored, and rejoins with the rejoin delays (1/2/5/10 s, then 10 s). A push that waits for a reply fails when its own timeout ends. - On a join in flight, the `phx_error` counts as a failed join attempt. Subscribe keeps waiting. - A confirmed rejoin reports the channel as subscribed again. - A socket close during the delay cancels it. The channel rejoins when the socket opens. - `phx_close` removes the channel and does not rejoin. The rules follow `@supabase/phoenix` 0.4.5 `channel.js`. The state diagram gains the `phx_error` and `phx_close` transitions. `presence_state.md` rule 5 assumes this rejoin, and the new section links it. That file is on `main`, so the link resolves once #304 merges. Context: SDK-2609 (supabase-swift v3 does not rejoin after a server `phx_error`).
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.
Adds Realtime specs for connection recovery:
realtime.client.connect: when the client reconnects, attempt counting (reset on socket open), no attempt limit, and the default full-jitter curve (base 1 s, cap 30 s). Applies to every SDK, whether or not it exposes the curve.realtime.channel.subscribe: channel rejoin delays (steps 1/2/5/10 s, 30 s after a rate-limit join error), join timeout, and immediate rejoin on socket open. Not configurable.realtime.configuration.reconnect_backoff: the optional caller-supplied attempt → delay function that replaces the default curve; negative delays count as zero.realtime.configuration.heartbeat_interval: heartbeat cadence (a fixed beat, default 25 s), which replies count, and the missing reply → close → reconnect sequence. A missing reply is detected within two intervals of the last reply.Context: supabase-swift v3
RealtimeClientOptionsrework (SDK-2103). Swift v3 keeps the reconnect curve internal.realtime.configuration.reconnect_backoffis planned for removal in a separatefeat(realtime)!:PR, after the SDKs drop it from theirsdk-compliance.yamlfiles. That PR deletes its spec too.Known divergences, to file as supabase-js issues once this merges: