node-slack-sdk icon indicating copy to clipboard operation
node-slack-sdk copied to clipboard

TypeError: Cannot read properties of undefined (reading 'type') at SocketModeClient.onWebSocketMessage

Open levenleven opened this issue 10 months ago • 16 comments

Sometimes we get an error due to event.payload.event being undefined

https://github.com/slackapi/node-slack-sdk/blob/039bd050cd736d666d063397067cb014adf23711/packages/socket-mode/src/SocketModeClient.ts#L344

TypeError: Cannot read properties of undefined (reading 'type')
    at SocketModeClient.onWebSocketMessage (/app/node_modules/@slack/socket-mode/dist/SocketModeClient.js:620:43)
    at WebSocket.onMessage (/app/node_modules/ws/lib/event-target.js:132:16)
    at WebSocket.emit (node:events:514:28)
    at Receiver.receiverOnMessage (/app/node_modules/ws/lib/websocket.js:1070:20)
    at Receiver.emit (node:events:514:28)
    at Receiver.dataMessage (/app/node_modules/ws/lib/receiver.js:517:14)
    at Receiver.getData (/app/node_modules/ws/lib/receiver.js:435:17)
    at Receiver.startLoop (/app/node_modules/ws/lib/receiver.js:143:22)
    at Receiver._write (/app/node_modules/ws/lib/receiver.js:78:10)
    at writeOrBuffer (node:internal/streams/writable:447:12)
    at _write (node:internal/streams/writable:389:10)
    at Receiver.Writable.write (node:internal/streams/writable:393:10)
    at TLSSocket.socketOnData (/app/node_modules/ws/lib/websocket.js:1164:35)
    at TLSSocket.emit (node:events:514:28)

Packages:

Select all that apply:

  • [ ] @slack/web-api
  • [ ] @slack/rtm-api
  • [ ] @slack/webhooks
  • [ ] @slack/oauth
  • [x] @slack/socket-mode
  • [ ] @slack/types
  • [ ] I don't know

Reproducible in:

The Slack SDK version

"@slack/socket-mode": "1.3.6"

Node.js runtime version

v20.9.0

OS info

#141~20.04.1-Ubuntu SMP Thu Jan 16 18:38:51 UTC 2025

Steps to reproduce:

N/A

Expected result:

Missing payload handled gracefully

Actual result:

Unhandled error

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. :bow:

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

levenleven avatar Mar 06 '25 06:03 levenleven

HI @levenleven! Thanks for bringing this to our attention. Unfortunately, we'll need more information in order to begin to debug and remedy what is going on here. If you're able to provide which event(s) that this error is occurring for, that'd be a great start.

misscoded avatar Mar 06 '25 18:03 misscoded

@misscoded thanks for looking into this. We subscribe to message events using bolt sdk (e.g. app.message(...)).

levenleven avatar Mar 07 '25 11:03 levenleven

Are message events the only events that your app listens for/subscribes to then? On your end and with your own logs, are you able to narrow down which specific message event type is causing the issue?

misscoded avatar Mar 07 '25 22:03 misscoded

Sorry, missed we also have app.action subscription. So only these two, message and action.

This is not reproducible (at least now), we've got ~ 20 such errors between Mar 5, 2025 10:40:00 PM UTC and Mar 6, 2025 10:51:30 PM UTC

On your end and with your own logs, are you able to narrow down which specific message event type is causing the issue

No, as this is happening not in application but in framework code.

levenleven avatar Mar 09 '25 07:03 levenleven

No worries! If you provide us your app ID, we might be able to look into the logs and figure out what the event in question is.

misscoded avatar Mar 13 '25 21:03 misscoded

Thanks! App id is A02V1ADGH5F

levenleven avatar Mar 17 '25 06:03 levenleven

Few other occasions

  • Mar 12, 2025 9:42:02 PM UTC - Mar 12, 2025 9:49:31 PM UTC
  • Mar 15, 2025 9:48:01 PM UTC - Mar 15, 2025 9:50:30 PM UTC
  • Mar 17, 2025 9:30:01 PM UTC - Mar 17, 2025 9:36:31 PM UTC

levenleven avatar Mar 18 '25 06:03 levenleven

@misscoded Is there anything else I can do to help with the investigation?

levenleven avatar Apr 03 '25 05:04 levenleven

👋 It looks like this issue has been open for 30 days with no activity. We'll mark this as stale for now, and wait 10 days for an update or for further comment before closing this issue out. If you think this issue needs to be prioritized, please comment to get the thread going again! Maintainers also review issues marked as stale on a regular basis and comment or adjust status if the issue needs to be reprioritized.

github-actions[bot] avatar May 05 '25 00:05 github-actions[bot]

Last seen on Apr 16, so maybe fixed on server side, or we just didn't receive some specific event type that causes this.

levenleven avatar May 05 '25 05:05 levenleven

👋 It looks like this issue has been open for 30 days with no activity. We'll mark this as stale for now, and wait 10 days for an update or for further comment before closing this issue out. If you think this issue needs to be prioritized, please comment to get the thread going again! Maintainers also review issues marked as stale on a regular basis and comment or adjust status if the issue needs to be reprioritized.

github-actions[bot] avatar Jun 16 '25 00:06 github-actions[bot]

Still happening periodically.

levenleven avatar Jun 16 '25 08:06 levenleven

👋 It looks like this issue has been open for 30 days with no activity. We'll mark this as stale for now, and wait 10 days for an update or for further comment before closing this issue out. If you think this issue needs to be prioritized, please comment to get the thread going again! Maintainers also review issues marked as stale on a regular basis and comment or adjust status if the issue needs to be reprioritized.

github-actions[bot] avatar Jul 28 '25 00:07 github-actions[bot]

keep

levenleven avatar Jul 28 '25 05:07 levenleven

Hey @levenleven! 👋 I'm catching up on this thread now and noticed @slack/[email protected] is used when this error is found.

The latest release right now is @slack/[email protected] and I'm wondering if updating to this version resolves this? 🤖

zimeg avatar Jul 29 '25 17:07 zimeg

Hey @zimeg, looks like the same error after upgrade to "@slack/socket-mode": "2.0.4"

TypeError: Cannot read properties of undefined (reading 'type')
    at SocketModeClient.<anonymous> (/app/node_modules/@slack/socket-mode/dist/src/SocketModeClient.js:302:47)
    at Generator.next (<anonymous>:null:null)
    at /app/node_modules/@slack/socket-mode/dist/src/SocketModeClient.js:41:71
    at new Promise (<anonymous>:null:null)
    at __awaiter (/app/node_modules/@slack/socket-mode/dist/src/SocketModeClient.js:37:12)
    at SocketModeClient.onWebSocketMessage (/app/node_modules/@slack/socket-mode/dist/src/SocketModeClient.js:263:16)
    at SocketModeClient.emit (/app/node_modules/eventemitter3/index.js:182:35)
    at WebSocket.<anonymous> (/app/node_modules/@slack/socket-mode/dist/src/SlackWebSocket.js:87:33)
    at WebSocket.emit (node:events:524:28)
    at Receiver.receiverOnMessage (/app/node_modules/ws/lib/websocket.js:1220:20)
    at Receiver.emit (node:events:524:28)
    at Receiver.dataMessage (/app/node_modules/ws/lib/receiver.js:596:14)
    at Receiver.getData (/app/node_modules/ws/lib/receiver.js:496:10)
    at Receiver.startLoop (/app/node_modules/ws/lib/receiver.js:167:16)
    at Receiver._write (/app/node_modules/ws/lib/receiver.js:94:10)
    at writeOrBuffer (node:internal/streams/writable:572:12)
    at _write (node:internal/streams/writable:501:10)
    at Receiver.Writable.write (node:internal/streams/writable:510:10)
    at TLSSocket.socketOnData (/app/node_modules/ws/lib/websocket.js:1355:35)
    at TLSSocket.emit (node:events:524:28)
    at addChunk (node:internal/streams/readable:561:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
    at TLSSocket.Readable.push (node:internal/streams/readable:392:5)
    at TLSWrap.onStreamRead (node:internal/stream_base_commons:191:23)
    at TLSWrap.callbackTrampoline (node:internal/async_hooks:130:17)

https://github.com/slackapi/node-slack-sdk/blob/0ddbaf7c1fd3746b0e0c94c4168bea3bef3fd58b/packages/socket-mode/src/SocketModeClient.ts#L344-L345

So event.payload.event here is undefined.

levenleven avatar Aug 05 '25 05:08 levenleven