slackapi / bolt-js

A framework to build Slack apps using JavaScript
https://slack.dev/bolt-js
MIT License
2.74k stars 392 forks source link

socket-mode:SocketModeClient:0 Received "disconnect" (reason: too_many_websockets) message - will attempt reconnect #2238

Closed ropiDK closed 1 week ago

ropiDK commented 1 week ago

(Filling out the following with as much detail as you can provide will help us answer your question sooner.)

@slack/bolt version

"@slack/bolt": "^3.19.0"

Your App and Receiver Configuration

    token: process.env.SLACK_BOT_TOKEN,
    appToken: process.env.SLACK_APP_TOKEN,
    socketMode: true,
    logLevel: LogLevel.DEBUG, 
    scopes: [
        'commands',
        'chat:write',
        'chat:write.public',
        'channels:read',
        'channels:history',
        'groups:history',
        'im:history',
        'app_mentions:read',
    ],
});

Node.js runtime version

v20.16.0

Steps to reproduce:

  1. npm start
  2. error too_many_websockets
  3. already create new app level token but still cannot resolved

Expected result:

App Running

Actual result:

socket-mode:SocketModeClient:0 Received a message on the WebSocket: {"type":"disconnect","reason":"too_many_websockets","debug_info":{"host":"applink-10"}}
[DEBUG]  socket-mode:SocketModeClient:0 Received "disconnect" (reason: too_many_websockets) message - will attempt reconnect
/Users/ropi/app-slack/node_modules/finity/lib/core/StateMachine.js:76
      throw new Error('Unhandled event \'' + event + '\' in state \'' + this.currentState + '\'.');
            ^

Error: Unhandled event 'server explicit disconnect' in state 'connecting'.
    at StateMachine.handleUnhandledEvent (/Users/ropi/app-slack/node_modules/finity/lib/core/StateMachine.js:76:13)
    at /Users/ropi/app-slack/node_modules/finity/lib/core/HierarchicalStateMachine.js:79:33
    at TaskScheduler.execute (/Users/ropi/app-slack/node_modules/finity/lib/core/TaskScheduler.js:29:7)
    at TaskScheduler.enqueue (/Users/ropi/app-slack/node_modules/finity/lib/core/TaskScheduler.js:19:12)
    at HierarchicalStateMachine.handle (/Users/ropi/app-slack/node_modules/finity/lib/core/HierarchicalStateMachine.js:72:24)
    at SocketModeClient.onWebSocketMessage (/Users/ropi/app-slack/node_modules/@slack/bolt/node_modules/@slack/socket-mode/dist/SocketModeClient.js:608:31)
    at WebSocket.onMessage (/Users/ropi/app-slack/node_modules/@slack/bolt/node_modules/ws/lib/event-target.js:132:16)
    at WebSocket.emit (node:events:519:28)
seratch commented 1 week ago

Thanks for taking the time to write and we're sorry for the disruption. Please check https://github.com/slackapi/bolt-js/issues/2225 for updates.

ropiDK commented 1 week ago

the issue still on investigation right? i got this issue about few days ago... createing new app level token cannot resolve the problem

filmaj commented 1 week ago

@ropiDK it is not in investigation. It is a design fault with socket-mode v1.x. socket-mode v2 fixes the issue. There is a bolt v4 release candidate available for use that uses socket-mode v2. You can try using that instead.

However, please pay close attention to the underlying reason for why the Slack server asked your app to reconnect:

{"type":"disconnect","reason":"too_many_websockets"

For some reason, your app is trying to initiate more than the maximum allowed 10 concurrent socket mode connections. Please see my comment in the issue @seratch mentioned here for details: https://github.com/slackapi/bolt-js/issues/2225#issuecomment-2326407652