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

too_many_websockets causes Cannot read properties of undefined (reading 'event') #2116

Closed
Ericxxt opened this issue May 17, 2024 · 5 comments
Labels
question M-T: User needs support to use the project

Comments

@Ericxxt
Copy link

Ericxxt commented May 17, 2024

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

@slack/bolt version

3.15.0

Refer to your package.json

Your App and Receiver Configuration

const slackApp = new App({
  token: process.env.SLACK_BOT_TOKEN,
  signingSecret: process.env.SLACK_SIGNING_SECRET,
  socketMode: true,
  appToken: process.env.SLACK_APP_TOKEN,
  port: PORT,
  logLevel: LogLevel.DEBUG
});

Node.js runtime version

v21.7.2

Steps to reproduce:

(Share the commands to run, source code, and project settings)

I just added a statement about event.user === plan.operator in current bolt app as below:

slackApp.event('reaction_added', async ({ event, client }) => {
  if (event.reaction === CHECKED_REACTION && event.user === object.operator)

It caused

[DEBUG]  socket-mode:SocketModeClient:0 Received a message on the WebSocket: {"type":"disconnect","reason":"too_many_websockets","debug_info":{"host":"applink-8"}}
[ERROR]   An unhandled error occurred while Bolt processed (type: undefined, error: TypeError: Cannot read properties of undefined (reading 'event'))
slackApp.event('reaction_added', async ({ event, client }) => {
  if (event.reaction === CHECKED_REACTION && event!.user === object.operator)

But if I apply with event!, no such error for undefined (reading 'event') produced nor too_many_websockets issue

Expected result:

(Tell what you expected to happen)

Actual result:

(Tell what actually happened with logs, screenshots)

Requirements

For general questions/issues about Slack API platform or its server-side, could you submit questions at https://my.slack.com/help/requests/new instead. 🙇

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

@filmaj
Copy link
Contributor

filmaj commented May 18, 2024

This should not be an error anymore in bolt v3.18 or newer.

@filmaj filmaj added question M-T: User needs support to use the project and removed untriaged labels May 18, 2024
@Ericxxt
Copy link
Author

Ericxxt commented May 20, 2024

This should not be an error anymore in bolt v3.18 or newer.

Thank you, any description link related to the fixed issue?

@seratch
Copy link
Member

seratch commented May 20, 2024

Please upgrade the underlying @slack/socket-mode library to this version: https://github.com/slackapi/node-slack-sdk/releases/tag/%40slack%2Fsocket-mode%401.3.5 With the upgrade, this issue should be resolved.

@Ericxxt
Copy link
Author

Ericxxt commented May 30, 2024

Thank you, I'll upgrade the version!

@Ericxxt Ericxxt closed this as completed May 30, 2024
@filmaj
Copy link
Contributor

filmaj commented May 30, 2024

Sorry just saw this! @Ericxxt the following change in socket-mode 1.3.5 fixes the issue in this thread:

All type:disconnect messages from the Slack backend now do not raise a slack_event event; this led to problems, particularly for users of bolt-js.

The details here are:

  • bolt-js listens on slack_event events raised by socket-mode, to know when e.g. a new event is delivered to the app when the app is connected over socket mode
  • in the case that your app has more than the maximum allowed concurrent websocket connections open (10), Slack backend will send messages to your app that look like {type:"disconnect", reason: "too_many_websockets"}
  • older versions of the socket-mode package would raise all type:disconnect messages as actual slack_events. <-- this was incorrect behaviour
  • when bolt-js went to parse these raised socket-mode events, it assumed the existence of certain properties on this event payload, like body. In this scenario, body is undefined, so when bolt went to process the event, it tried to infer certain sub-properties and eventually hit this line, which is what caused the error you saw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question M-T: User needs support to use the project
Projects
None yet
Development

No branches or pull requests

3 participants