Repository navigation
Conversation
Open the next Socket Mode connection before closing the old one when Slack sends type: disconnect, and skip the consecutive-failure delay. Fixes slackapi#2767
🦋 Changeset detectedLatest commit: 4bd3f96 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 |
Abort an in-flight Slack-requested refresh if the new socket closes before hello, the old socket dies while connecting, or hello times out, then reconnect with the usual backoff. Route acks to the retiring socket while the replacement is still connecting.
During a Slack-requested refresh the replacement WebSocket can be OPEN before hello. Send acks on the retiring socket until the handshake completes, and emit disconnected only once if disconnect() runs mid-refresh.
hippi345
marked this pull request as ready for review
October 17, 2026 02:16
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
When Slack sends
{"type":"disconnect"}(includingrefresh_requested),@slack/socket-modeused to close the current WebSocket before opening a replacement and then treat the close as a reconnection failure. That left apps without a connection for several seconds.This change handles a Slack-requested
disconnectinSocketModeClientby opening the next connection immediately and keeping the old socket until the new one receiveshello. A successful refresh is not counted as a consecutive failure.If the replacement never becomes ready, the client does not stay stuck: a
closeon the new socket beforehello, acloseon the old socket while the refresh is still pending, or ahellotimeout (clientPingTimeout) aborts the in-flightstart(), closes leftover sockets, and recovers throughdelayReconnectAttemptso real failures still back off.Until the replacement has received
hello, acks are written on the old socket even if the new WebSocket is alreadyOPEN. The remaining limitation is acks already in flight at the moment of switchover (whenhelloarrives and the old socket is closed).Fixes #2767.
Changes
type: disconnectmessage with auto-reconnect enabled, callstart()right away instead ofwebsocket.disconnect().SlackWebSocketuntil the replacement handshake completes, then close it.hello, the old socket dies during the refresh, orhellodoes not arrive in time: clear the refresh flag, emitdisconnectedsostart()settles, close leftover sockets, and scheduledelayReconnectAttempt.apps.connections.opencannot attach a socket after recovery has already started.refreshInProgressis true and the old socket is still open,send()/ acks use the old socket. The client switches to the new socket only afterhello. The only remaining limitation is acks in flight at the moment of that switchover.disconnect()during a refresh emitsdisconnectedonce.delayReconnectAttemptpath.Testing
should acknowledge on the old socket while the new socket is OPEN but has not received hellofails one4958bb(acks followedisActive()/ WebSocket OPEN) and passes after this change.closerecovery, acks while connecting, a singledisconnectedifdisconnect()runs mid-refresh, auto-reconnect disabled.npm test --workspace=packages/socket-mode(unit + integration) on Node 22npm run lintRequirements
This change was prepared with AI assistance and reviewed by the author.