Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disconnection in development mode (too_many_websockets) #394

Open
wnqueiroz opened this issue Aug 29, 2024 · 2 comments
Open

Disconnection in development mode (too_many_websockets) #394

wnqueiroz opened this issue Aug 29, 2024 · 2 comments

Comments

@wnqueiroz
Copy link

Describe the bug

Hi guys, I'm having a problem when running a NestJS project with yarn start:dev. Below is the output:

[Nest] 1208570  - 08/29/2024, 9:05:57 AM   DEBUG [Slack] apiCall('auth.test') end
[Nest] 1208570  - 08/29/2024, 9:05:57 AM   DEBUG [Slack] Primary WebSocket open event received (connection established)
[Nest] 1208570  - 08/29/2024, 9:05:57 AM   DEBUG [Slack] Transitioning to state: connecting:handshaking
[Nest] 1208570  - 08/29/2024, 9:05:57 AM   DEBUG [Slack] Received a message on the WebSocket: {"type":"disconnect","reason":"too_many_websockets","debug_info":{"host":"applink-11"}}
[Nest] 1208570  - 08/29/2024, 9:05:57 AM   DEBUG [Slack] Received "disconnect" (reason: too_many_websockets) message - will attempt reconnect
/home/wnqueiroz/bot-api/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 (/home/wnqueiroz/bot-api/node_modules/finity/lib/core/StateMachine.js:76:13)
    at /home/wnqueiroz/bot-api/node_modules/finity/lib/core/HierarchicalStateMachine.js:79:33
    at TaskScheduler.execute (/home/wnqueiroz/bot-api/node_modules/finity/lib/core/TaskScheduler.js:29:7)
    at TaskScheduler.enqueue (/home/wnqueiroz/bot-api/node_modules/finity/lib/core/TaskScheduler.js:19:12)
    at HierarchicalStateMachine.handle (/home/wnqueiroz/bot-api/node_modules/finity/lib/core/HierarchicalStateMachine.js:72:24)
    at SocketModeClient.onWebSocketMessage (/home/wnqueiroz/bot-api/node_modules/@slack/socket-mode/src/SocketModeClient.ts:737:25)
    at WebSocket.onMessage (/home/wnqueiroz/bot-api/node_modules/ws/lib/event-target.js:132:16)
    at WebSocket.emit (node:events:517:28)
    at Receiver.receiverOnMessage (/home/wnqueiroz/bot-api/node_modules/ws/lib/websocket.js:1070:20)
    at Receiver.emit (node:events:517:28)

Anyone else experiencing this? I'm performing the integration using socket mode.

It looks like there's a problem when transitioning to connecting:handshaking.

Environment

  • Node.js v18.20.4
  • NestJS@^10.0.0
  • nestjs-slack-bolt@^1.1.1
@bamada
Copy link
Owner

bamada commented Sep 12, 2024

Hi, sorry for the delay. Were you able to fix the issue? If not, could you please provide steps to reproduce it? I haven't encountered this error before.

@wnqueiroz
Copy link
Author

Hello @bamada, I haven't had time to explore the problem further and work on it yet, so I'll share some of the research I've done here.

The first thing I had to do was understand who is using the finity library:

➜  npm why finity
[email protected]
node_modules/finity
  finity@"^0.5.4" from @slack/[email protected]
  node_modules/@slack/socket-mode
    @slack/socket-mode@"^1.3.6" from @slack/[email protected]
    node_modules/@slack/bolt
      @slack/bolt@"^3.21.1" from the root project
    @slack/socket-mode@"^1.3.3" from @slack/[email protected]
    node_modules/nestjs-slack-bolt/node_modules/@slack/bolt
      @slack/bolt@"3.18.0" from [email protected]
      node_modules/nestjs-slack-bolt
        nestjs-slack-bolt@"^1.1.1" from the root project

It is used by the @slack/[email protected] dependency which provides Socket Mode support.

It seems to me that there is an unhandled server explicit disconnect event in the state machine transitions configuration.

Which led me to wonder why the server would be blocking the connection...

I found this related issue: slackapi/bolt-js#2113, which directed me to this one: slackapi/node-slack-sdk#1787

And what happens is that the @slack/[email protected] version has an outdated and confusing architecture by having only one state machine to handle the transitions.

We can see more details in this comment: slackapi/node-slack-sdk#1787 (comment)

Where the most relevant part is:

This issue is resolved in socket-mode 2.x, as the architecture has completely changed. Socket-mode 2.0 is available in bolt 4.0.0 rc1, and has been used successfully by some customers who have adopted it early.

I can submit a PR with preliminary tests of @slack/bolt/4.0.0-rc.1 if it makes sense and is on the project roadmap.

Note 1: Since the issue occurs outside of bamada/nest-slack-bolt I haven't been able to think of a quick fix for it yet.

Note 2: The issue has only affected development mode for now, I haven't validated if the same occurs in production yet, but it does indeed "restart" the app.

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

No branches or pull requests

2 participants