Commit bb48fbe
Always unsubscribe from the internal channel on Connection#close
A connection subscribes to its internal channel unconditionally during
#initialize (via subscribe_to_internal_channel), but #close only tore
that subscription down inside the `if channels_to_close` branch. A
connection that opened but never subscribed to a user channel therefore
left its `cable_internal/<id>` subscription dangling on the backend after
disconnecting — a small but real leak.
Move unsubscribe_from_internal_channel out of that branch so it always
runs on close, mirroring the unconditional subscribe in #initialize.
Because #close now always reaches the backend, guard the call against
IO::Error: Server#shutdown closes the backend connections *before*
closing each Connection, so during a restart/shutdown the unsubscribe
can hit an already-closed backend. Without the guard that IO::Error
escapes #close and breaks the shutdown loop (it surfaced as the handler
"restarts the server if too many errors" spec failing). This mirrors the
existing defensive handling in #initialize and Server#shutdown.
Adds regression coverage to the existing "#close ... without channel
subscriptions" example via a Connection subclass that records the
internal-channel hook calls while still delegating to the real backend.
Fixes #109
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BMW1EsdCMExBhm3tg7TQhs1 parent bfdb55d commit bb48fbe
2 files changed
Lines changed: 59 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
9 | 21 | | |
10 | 22 | | |
11 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
12 | 27 | | |
13 | 28 | | |
14 | 29 | | |
| |||
604 | 619 | | |
605 | 620 | | |
606 | 621 | | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
607 | 650 | | |
608 | 651 | | |
609 | 652 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
100 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
101 | 115 | | |
102 | 116 | | |
103 | 117 | | |
| |||
0 commit comments