Catch backend failures during Connection#initialize. Fixes #105#106
Merged
jwoertink merged 1 commit intoMay 7, 2026
Merged
Conversation
…clean close code instead of 1006. Fixes cable-cr#105 When the backend (e.g. Redis) connection is dead, subscribe_to_internal_channel raised IO::Error which escaped the narrow rescue (UnauthorizedConnectionException only) and propagated through HTTP::WebSocketHandler, tearing down the TCP socket without a close frame. Clients saw close code 1006 with zero messages received, and recovery only happened on process restart. Widen the rescue to catch any Exception, mark the connection rejected, send a proper InternalServerError (1011) close frame, and report via on_error so the failure is visible to operators. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
5 tasks
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.
Summary
Fixes #105 — when the backend (e.g. Redis) connection is dead, every WebSocket upgrade was silently killed mid-handshake with close code 1006 and zero messages received, only recovering on process restart.
Connection#initialize's rescue only caughtUnauthorizedConnectionException. TheIO::Errorraised bysubscribe_to_internal_channelagainst a broken Redis socket escaped toHTTP::WebSocketHandler, which tore down the TCP socket without a close frame.This widens the rescue to any
Exception:next if … connection_rejected?skipsadd_connection/welcome cleanly)unsubscribe_from_internal_channel(swallowing further backend errors so the original isn't masked)InternalServerError(1011) close frame so clients get a meaningful signal instead of 1006on_errorso operators see the failureRecovery of the backend itself (issue's options #1 and #3) lives in the
cable-redisshard and isn't addressed here — this PR is the close-code fix only.Test plan
connection_spec.crusing aFailingSubscribeBackend(aCable::DevBackendsubclass that raisesIO::Erroronsubscribe) verifies the rescue path: socket closed, connection rejected,on_errorinvoked.🤖 Generated with Claude Code