Close fiber_channel on Server#shutdown to avoid fiber leak. Fixes #110#111
Open
russ wants to merge 1 commit into
Open
Close fiber_channel on Server#shutdown to avoid fiber leak. Fixes #110#111russ wants to merge 1 commit into
russ wants to merge 1 commit into
Conversation
…le-cr#110 During Server#shutdown the fiber_channel was never closed, so the process_subscribed_messages fiber was left blocked on receive against an orphaned channel. Since Cable.restart builds a fresh Server (with a fresh channel) on every restart, each restart leaked a fiber and channel. Close the channel at the end of shutdown, and switch the receive loop to receive? so the fiber exits cleanly instead of raising Channel::ClosedError on a closed channel. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BMW1EsdCMExBhm3tg7TQhs
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
During
Server#shutdownthefiber_channel(::Channel({String, String})) was never closed. Theprocess_subscribed_messagesfiber reads from it in a forever-loop (while received = fiber_channel.receive), and the producer side lives in the externalcable-redisshard (Cable.server.fiber_channel.send(...)).Because
Cable.restartbuilds a brand-newServer— with a brand-newfiber_channel— on every restart, each shutdown left the old fiber blocked onreceiveagainst an orphaned channel. That's a fiber + channel leak that accumulates across restarts.Fixes #110.
Changes
Server#shutdownnow callsfiber_channel.closeafter closing connections (where the issue author suggested).receivetoreceive?. This is necessary because callingreceiveon a closed channel raisesChannel::ClosedError, which would crash the spawned fiber with an unhandled exception.receive?returnsnilon close, so the loop exits cleanly.Tests
spec/cable/server_spec.crasserting that aftershutdownthefiber_channelis closed and a subsequentsendraises.🤖 Generated with Claude Code