Skip to content

fix(slack): log socket mode listener failures instead of crashing - #1174

Open
mutru wants to merge 1 commit into
vercel:mainfrom
mutru:fix/slack-socket-ack-rejection
Open

mutru wants to merge 1 commit into
vercel:mainfrom
mutru:fix/slack-socket-ack-rejection

Conversation

@mutru

@mutru mutru commented Nov 16, 2026 •

Copy link
Copy Markdown

Summary

If a Socket Mode event arrives while the socket is closing or reconnecting, ack() rejects with slack_socket_mode_no_reply_received_error. SocketModeClient emits slack_event without awaiting its listeners, so the rejection is unhandled and Node exits.

We hit this during graceful shutdowns after deployment. chat.shutdown() disconnects the socket, an event lands in that window, and the process crashes before it finishes its own cleanup:

[ERROR]  socket-mode:SocketModeClient:0 Failed to send a message as the client has no active connection
Error: Failed to send a WebSocket message as the client is not ready
    at SocketModeClient.send (@slack/socket-mode/src/SocketModeClient.ts:387:12)
    at ack (@slack/socket-mode/src/SocketModeClient.ts:340:18)
    at _SlackAdapter.routeSocketEvent (@chat-adapter/slack/dist/index.js:3107:15)
  code: 'slack_socket_mode_no_reply_received_error'

The new instance then got the event as a retry (retry_reason: "timeout"), so the event wasn't lost; the process exit was the only harm. The same path can fire on any reconnect, not only at shutdown. Webhook mode isn't affected, since its acknowledgement is the HTTP response.

Both slack_event listeners, in startSocketMode() and runSocketModeListener(), now run their work through handleSocketEventSafely(), which logs Error handling socket mode event with the event type and error instead of rejecting.

This follows the Discord adapter, whose Gateway raw listener has the same problem, since discord.js doesn't await listeners either: enqueueOrderedForward() catches the listener's work and logs Failed to forward Gateway event.

Test plan

  • Two new tests, one per listener, call the registered slack_event handler with an ack() that rejects, and assert that it resolves and logs the error. Both fail without the fix.
  • pnpm validate passes, except the example-nuxt-chat build, which fails locally with ENAMETOOLONG in Nitro's node_modules traversal (a macOS path-length limit in my checkout, unrelated to this change). The other 30 build tasks pass.

Checklist

  • All commits are signed and verified
  • All commits are signed off for the DCO (git commit -s)
  • pnpm validate passes (except the local example-nuxt-chat build noted above)
  • Changeset added (or N/A — see CONTRIBUTING.md)
  • Documentation updated (or N/A): N/A, the docs don't describe this failure

🤖 Generated with Claude Code

When a Socket Mode event arrives while the socket is closing or
reconnecting, ack() rejects with slack_socket_mode_no_reply_received_error.
SocketModeClient emits slack_event without awaiting its listeners, so the
rejection is unhandled and Node exits. We saw this in production during
graceful shutdowns: chat.shutdown() disconnects the socket, an event lands
in that window, and the process dies before finishing its cleanup.

Both slack_event listeners, in startSocketMode() and
runSocketModeListener(), now run their work through
handleSocketEventSafely(), which logs "Error handling socket mode event".
Slack redelivers an event that wasn't acknowledged, so it isn't lost.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Otto Hilska <otto@swarmia.com>
@vercel

vercel Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

@mutru is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

@mutru
mutru marked this pull request as ready for review November 16, 2026 23:01
@mutru
mutru requested a review from a team November 16, 2026 23:01

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant