fix(realtime): reset channel state on phx_error#1109
Open
AndroidPoet wants to merge 1 commit into
Open
Conversation
grdsdev
approved these changes
Jul 9, 2026
Coverage Report for CI Build 29045564135Coverage increased (+0.03%) to 83.519%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
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.
Problem
When a subscribed channel receives a
phx_errorframe (a channel-level error the server sends without closing the socket, for example a replication error or an authorization change),onMessageonly logs it. The channel stays.subscribedeven though it is dead server-side, sostatusnever reflects the error and observers keep waiting for events that never arrive. During a subscribe attempt aphx_erroris likewise ignored, so the join waits out the full timeout instead of failing fast.realtime-js treats
phx_erroras a channel error and drops the channel so it can rejoin.Fix
Route
.errorthrough the existingdidReceiveClose(), the same reset the.closecase uses. Its own doc already covers this case ("phx_close or system error that should drop the channel"): it clears the join ref and pending pushes and moves the channel to.unsubscribed. The channel stays registered on the socket, so it rejoins on the next reconnect.If you would prefer the channel to also schedule an immediate per-channel rejoin (as realtime-js does) rather than waiting for the next socket reconnect, I am happy to add that.
Tests
Added
testChannelErrorResetsSubscribedStatus: drives a channel to.subscribedover a fake socket, sends aphx_errorframe, and asserts the channel transitions to.unsubscribed. It fails before this change (the channel stays.subscribed) and passes after. FullRealtimeTestssuite passes (241 tests). No public API change.