fix(socket-mode): route ping/pong diagnostics by identity, not instanceof (#2743) - #2747
Open
WilliamBergamin wants to merge 5 commits into
Open
WilliamBergamin wants to merge 5 commits into
WilliamBergamin wants to merge 5 commits into
Conversation
…ceof (#2743) The undici ping/pong diagnostics channels are process-global: every undici WebSocket in the process publishes to them, including Node's built-in global WebSocket, which is a separate undici copy from the SDK's import. The old guard checked `message.websocket instanceof WebSocket` before the identity check, so a frame from any other undici copy failed instanceof and logged a spurious WARN on an otherwise healthy Slack connection (issue reporter: a nostr-tools relay pinging every 30s). Match by reference identity (`message.websocket === this.websocket`) instead, folding identity and shape into one guard that returns silently for frames that are not this socket's. Slack's own frames are unaffected. Adds tests covering foreign-copy and same-socket frames on both channels. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
🦋 Changeset detectedLatest commit: efabc23 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❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2747 +/- ##
==========================================
+ Coverage 89.15% 89.28% +0.12%
==========================================
Files 65 65
Lines 10442 10433 -9
Branches 480 478 -2
==========================================
+ Hits 9310 9315 +5
+ Misses 1100 1087 -13
+ Partials 32 31 -1
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
…cket Same logic, expressed as early-return if statements instead of one boolean chain. Reads more clearly and matches the guard shape the file used before. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
The function name and guard clauses carry the intent; the comment was redundant. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
WilliamBergamin
marked this pull request as ready for review
September 22, 2026 17:17
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
Fixes #2743.
@slack/socket-modedrives its heartbeat by subscribing to undici'sundici:websocket:ping/undici:websocket:pongdiagnostics channels. Those channels are process-global: every undiciWebSocketin the process publishes to them, including Node's built-in globalWebSocket, which is a separate copy of undici from the one the SDK imports (even at the same version).In
SlackWebSocket.ts,pingHandler/pongHandlerranisPingPongMessage(message)first, and that guard requiredmessage.websocket instanceof WebSocketagainst the SDK'sundiciimport. A frame from a socket opened by any other undici copy fails thatinstanceof, so the handler loggedReceived unexpected ping diagnostics message formatat WARN before reaching themessage.websocket !== this.websocketidentity check that would have dropped it silently.Result: any library in the same process that opens a WebSocket via the global
WebSocketand receives pings makes a healthy Slack connection spam one WARN per foreign ping. (The reporter hit this with anostr-toolsrelay pinging every 30s.)The fix: match by reference identity (
message.websocket === this.websocket) instead ofinstanceof, and fold identity + shape into one guard that returns silently for frames that are not this socket's.instanceofwas only ever a proxy for identity, and it is cross-copy-fragile; reference equality is strictly stronger for routing and was already being computed one line too late. Slack's own frames pass exactly as before, so heartbeat behavior is unchanged.Adds unit tests (the first to exercise the diagnostics-channel path) covering both channels: a frame from a foreign undici copy is ignored with no WARN, and a frame for this socket is processed.
Requirements