Repository navigation
fix(socket-mode): stop orphaning the close-handshake timer on disconnect (#2771) - #2777
Open
WilliamBergamin wants to merge 2 commits into
Open
WilliamBergamin wants to merge 2 commits into
WilliamBergamin wants to merge 2 commits into
Conversation
…ocket closes mid-close (#2771) disconnect() armed a second 30s close-handshake timer when the socket was already CLOSED, losing the first. undici fires 'error' only after setting CLOSED, so a TCP drop after our close frame always hit this. The lost timer later logged a false handshake warning and emitted a second 'close', which could start a duplicate reconnect. - Clean up immediately when disconnect() finds the socket CLOSED. - Arm the timer before close(): on a CONNECTING socket undici fires 'error' and 'close' synchronously inside close(), so the re-entrant cleanup() now clears it instead of running before it is armed. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
🦋 Changeset detectedLatest commit: 94e0050 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2777 +/- ##
==========================================
- Coverage 89.40% 89.39% -0.02%
==========================================
Files 65 65
Lines 10545 10548 +3
Branches 478 480 +2
==========================================
+ Hits 9428 9429 +1
- Misses 1086 1087 +1
- Partials 31 32 +1
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
2 tasks
This branch has not been deployed
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
This pull request fixes a close-handshake timer that could outlive its connection in
SlackWebSocket.disconnect().Fixes #2771. Follow-up to #2710, which added the timer.
The bug:
disconnect()starts a 30s timer when it sends a close frame. In two cases that timer survived cleanup, then fired 30s later: a false "Peer did not complete the close handshake" warning and a secondcloseevent, which can trigger a duplicate reconnect.errorwith the socket already CLOSED, sodisconnect()started a second timer and lost the first.disconnect()on a CLOSED socket now cleans up right away.disconnect()is called before the connection opens. undici closes a connecting socket synchronously insideclose(), so cleanup ran before the timer was started.close().Note: when the connection drops, the client now receives
closebeforeerror.Not in this PR:
closeonly once per instance:client.disconnect()during a reconnect backoff relies on that extracloseto resolve.Testing
Each case has a new unit test that fails on
main.To check by hand against a build of this branch:
client.disconnect()while the socket is still connecting and wait 31s: oneclose, no warning.Requirements
🤖 Generated with Claude Code