Problem
When the gateway health monitor restarts a Slack socket-mode connection (reason: stale-socket), the @slack/[email protected] library has a race condition that can leave orphaned ping/pong intervals running.
What happens
- The health monitor detects a stale socket (no events for 30 min)
- It calls
channelManager.stopChannel() → abort() → app.stop()
app.stop() calls SocketModeClient.disconnect() which sets shuttingDown = true and sends a close frame
- Race: if the library's own ping timeout fires
SlackWebSocket.disconnect() before shuttingDown is set, the close event handler sees shuttingDown === false and schedules a reconnect via delayReconnectAttempt(this.start)
- The orphaned ping interval (1.6s cycle) keeps firing on the dead socket, logging "A pong wasn't received from the server before the timeout of 5000ms!" indefinitely
Impact
gateway.err.log grew to 111MB from pong timeout warnings (~3 warnings every 1.6 seconds across 3 Slack accounts)
- File descriptor accumulation over time (leaked websockets + intervals)
- Contributes to system instability on long-running gateways
Environment
Problem
When the gateway health monitor restarts a Slack socket-mode connection (reason:
stale-socket), the@slack/[email protected]library has a race condition that can leave orphaned ping/pong intervals running.What happens
channelManager.stopChannel()→abort()→app.stop()app.stop()callsSocketModeClient.disconnect()which setsshuttingDown = trueand sends a close frameSlackWebSocket.disconnect()beforeshuttingDownis set, thecloseevent handler seesshuttingDown === falseand schedules a reconnect viadelayReconnectAttempt(this.start)Impact
gateway.err.loggrew to 111MB from pong timeout warnings (~3 warnings every 1.6 seconds across 3 Slack accounts)Environment
@slack/[email protected]@slack/[email protected](2.0.6 has no fix for this — only cosmetic async/await changes)