Skip to content

fix(realtime)!: rejoin a channel after a server phx_error - #1744

Merged
grdsdev merged 1 commit into
mainfrom
guilhermesouza/sdk-2609-realtime-joined-channel-does-not-rejoin-after-a-server
Nov 5, 2026
Merged

grdsdev merged 1 commit into
mainfrom
guilhermesouza/sdk-2609-realtime-joined-channel-does-not-rejoin-after-a-server

Conversation

@grdsdev

@grdsdev grdsdev commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

What and why

A joined RealtimeChannel did not rejoin after the server sent phx_error for its current join. It went to .unsubscribed, and its streams stayed open but got no data. supabase-js rejoins with its rejoin backoff. This PR makes Swift do the same:

  • Subscribed channel: the channel fails pushes that wait for a reply with the new RealtimeError.Kind.channelError. It moves to .resubscribing(attempt: 1, retryIn: 1s, lastError: channelError) and joins again with RealtimeChannel.rejoinBackoff (1, 2, 5, then 10 s). A confirmed rejoin emits .resubscribed.
  • Join in flight: a phx_error counts as a failed attempt, so subscribe() keeps waiting instead of throwing channelClosedByServer.
  • No change: a phx_error for a stale join_ref is dropped, and phx_close still drops the channel.

In the core, phx_error now has its own handler, receiveChannelError, which reuses joinAttemptFailed. The DocC (ConnectionBehavior.md, Lifetime.md, subscribe()) and the v3 migration guide ("Silent changes" in docs/migrations/v3/Realtime.md) describe the new behavior. sdk-compliance.yaml lists the new kind.

Spec: the matching rule is in supabase/sdk#334, which is stacked on supabase/sdk#304.

Test evidence

  • Core state-machine tests in RealtimeCoreLeaveTests: subscribed and joining cases, backoff on a second error, a repeated error during the wait, a phx_error for a timed-out join, and unsubscribe() during the wait.
  • A shell test, ServerErrorRejoinTests, runs the full path on RealtimeTestHost with a test clock (no real sleeps): phx_error, the rejoin wait, the rejoin, and .resubscribed. It also checks that a pending push fails with channelError.
  • Updated three older tests that expected .unsubscribed.
  • swift test --filter RealtimeTests (macOS flags): Test run with 726 tests in 55 suites passed ... with 7 known issues (the 7 known issues were there before this change).
  • swiftlint lint --strict, ./scripts/format.sh, ./scripts/spell-check.sh, and ./scripts/check-compliance.sh are clean.
  • No integration test: a local Supabase stack cannot be made to send phx_error on demand, so the test host plays the server.

Fixes SDK-2609

A phx_error for the current join now makes the channel wait and join
again with the rejoin backoff (1, 2, 5, then 10 s), as supabase-js does.
A subscribed channel reports .resubscribing with the new
RealtimeError.Kind.channelError and emits .resubscribed when the rejoin
is confirmed. Pushes that wait for a reply fail with channelError. A
phx_error during a join counts as a failed attempt, so subscribe()
keeps waiting. A phx_error for a stale join_ref changes nothing, and
phx_close still drops the channel.

BREAKING CHANGE: a channel no longer becomes .unsubscribed after a
server phx_error, and subscribe() no longer throws channelClosedByServer
for one. See docs/migrations/v3/Realtime.md.

Fixes SDK-2609
@coderabbitai

coderabbitai Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 4 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0fa9b9c6-c331-4064-b80e-027cb9b39ef5
Commits

Reviewing files that changed from the base of the PR and between 0ca38f2 and 1f7659f.

Files selected for processing: 15

  • Sources/Realtime/Core/RealtimeCore+Leave.swift
  • Sources/Realtime/Core/RealtimeCore+Subscribe.swift
  • Sources/Realtime/Core/RealtimeCore.swift
  • Sources/Realtime/Realtime.docc/ConnectionBehavior.md
  • Sources/Realtime/Realtime.docc/Lifetime.md
  • Sources/Realtime/RealtimeChannel.swift
  • Sources/Realtime/RealtimeError.swift
  • Tests/RealtimeTests/Core/RealtimeCoreLeaveTests.swift
  • Tests/RealtimeTests/RealtimeChannelOnMessageTests.swift
  • Tests/RealtimeTests/RealtimeChannelTests.swift
  • Tests/RealtimeTests/RealtimeReconnectRecoveryTests.swift
  • Tests/RealtimeTests/RealtimeTestHost.swift
  • Tests/RealtimeTests/Shell/ServerErrorRejoinTests.swift
  • docs/migrations/v3/Realtime.md
  • sdk-compliance.yaml
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

⚠️ Capability matrix drift detected

The following capabilities are marked implemented in swift but have no registered symbols to verify:

  • auth.passkey.register_passkey (no symbols list — cannot confirm implementation exists)
  • auth.passkey.sign_in_with_passkey (no symbols list — cannot confirm implementation exists)
  • auth.passkey.delete_passkey (no symbols list — cannot confirm implementation exists)
  • auth.passkey.list_passkeys (no symbols list — cannot confirm implementation exists)
  • auth.passkey.update_passkey (no symbols list — cannot confirm implementation exists)
  • auth.passkey_admin.list_passkeys (no symbols list — cannot confirm implementation exists)
  • auth.passkey_admin.delete_passkey (no symbols list — cannot confirm implementation exists)
  • client.observability.trace_propagation (no symbols list — cannot confirm implementation exists)
  • database.using_modifiers.request_cancellation (no symbols list — cannot confirm implementation exists)
  • storage.file_buckets.resumable_upload (no symbols list — cannot confirm implementation exists)
  • storage.file_buckets.copy_cross_bucket (no symbols list — cannot confirm implementation exists)
  • storage.file_buckets.move_cross_bucket (no symbols list — cannot confirm implementation exists)
  • storage.file_buckets.url_cache_nonce (no symbols list — cannot confirm implementation exists)
  • storage.file_buckets.file_info_specific_version (no symbols list — cannot confirm implementation exists)
  • storage.file_buckets.move_specific_version (no symbols list — cannot confirm implementation exists)
  • storage.file_buckets.copy_specific_version (no symbols list — cannot confirm implementation exists)
  • storage.file_buckets.request_cancellation (no symbols list — cannot confirm implementation exists)
  • storage.vector_buckets.create_vector_bucket (no symbols list — cannot confirm implementation exists)
  • storage.vector_buckets.list_vector_buckets (no symbols list — cannot confirm implementation exists)
  • storage.vector_buckets.delete_vector_bucket (no symbols list — cannot confirm implementation exists)
  • storage.vector_buckets.access_vector_index (no symbols list — cannot confirm implementation exists)
  • storage.vector_buckets.create_index (no symbols list — cannot confirm implementation exists)
  • storage.vector_buckets.delete_index (no symbols list — cannot confirm implementation exists)
  • storage.vector_buckets.get_index (no symbols list — cannot confirm implementation exists)
  • storage.vector_buckets.list_indexes (no symbols list — cannot confirm implementation exists)
  • storage.vector_buckets.put_vectors (no symbols list — cannot confirm implementation exists)
  • storage.vector_buckets.get_vectors (no symbols list — cannot confirm implementation exists)
  • storage.vector_buckets.delete_vectors (no symbols list — cannot confirm implementation exists)
  • storage.vector_buckets.list_vectors (no symbols list — cannot confirm implementation exists)
  • storage.vector_buckets.query_vectors (no symbols list — cannot confirm implementation exists)
  • storage.vector_buckets.parallel_scan (no symbols list — cannot confirm implementation exists)
  • storage.analytics.create_analytics_bucket (no symbols list — cannot confirm implementation exists)
  • storage.analytics.list_analytics_buckets (no symbols list — cannot confirm implementation exists)
  • storage.analytics.delete_analytics_bucket (no symbols list — cannot confirm implementation exists)

These may have been renamed, removed, or never registered. Please update the capability matrix.
See: https://github.com/supabase/sdk/blob/main/packages/capability-matrix/docs/capability-matrix.md

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 42094534585

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage decreased (-0.01%) to 95.62%

Details

  • Coverage decreased (-0.01%) from the base build.
  • Patch coverage: 4 uncovered changes across 1 file (42 of 46 lines covered, 91.3%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
Sources/Realtime/Core/RealtimeCore+Leave.swift 43 39 90.7%
Total (2 files) 46 42 91.3%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 15822
Covered Lines: 15129
Line Coverage: 95.62%
Coverage Strength: 508223.8 hits per line

💛 - Coveralls

@grdsdev
grdsdev merged commit d0b82f9 into main Nov 5, 2026
47 checks passed
@grdsdev
grdsdev deleted the guilhermesouza/sdk-2609-realtime-joined-channel-does-not-rejoin-after-a-server branch November 5, 2026 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants