fix(channel): tear down orphaned WSClient on connect timeout (fixes #197) - #203
Open
Xuxchloris wants to merge 1 commit into
Open
fix(channel): tear down orphaned WSClient on connect timeout (fixes #197)#203Xuxchloris wants to merge 1 commit into
Xuxchloris wants to merge 1 commit into
Conversation
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.
Fixes #197
Problem
When the WebSocket handshake does not complete within
connect()'s timeout, the channel rejects withnot_connectedbut leaves the still-handshakingWSClientrunning in the background:There is also a second, independent unhandled-exception path inside
ws-client: aborting a CONNECTING socket (handshake watchdog orclose()) callsremoveAllListeners()first and thenterminate()/close(), and thewslibrary emits a lateerroron a terminated CONNECTING socket — with every listener removed that becomes anuncaughtException.Changes
channel/channel.ts: on connect timeout, force-close the orphanedWSClientbefore rejecting, so it cannot leak or keep retrying after the attempt is abandoned.channel/types.ts: newconnectTimeoutMsoption (default15000, previously hardcoded) so callers can tune the window.ws-client/index.ts: keep a no-operrorlistener afterremoveAllListeners()in both the handshake watchdog andclose(), so aborting a CONNECTING socket stays silent instead of crashing the process.channel/__tests__/connect-timeout.test.ts: new tests assertingconnect()rejects withnot_connectedand force-closes the orphaned client, and that a retry starts a fresh client.channel.md/channel.zh.md) updated for the new option.Verification
npx jest channel— 27 suites, 276 tests passing (including the 2 new tests).connect()itself gives up).