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

socket-mode(fix): do not handle message events twice #2059

Merged
merged 1 commit into from
Oct 2, 2024

Conversation

filmaj
Copy link
Contributor

@filmaj filmaj commented Oct 2, 2024

#2057 uncovered that the socket mode client was raising errors when parsing message Slack events. Turns out this was due to the fact that the Socket Mode client was listening on both Slack message events as well as the ws package's message event. When a web socket message would come in, the client would re-emit the event's type as a new message to be bubbled up. In the case of Slack message events, this would effectively mean they would be processed twice.

Fixes #2057.

@filmaj filmaj added bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented semver:patch pkg:socket-mode applies to `@slack/socket-mode` labels Oct 2, 2024
@filmaj filmaj added this to the [email protected] milestone Oct 2, 2024
@filmaj filmaj requested a review from zimeg October 2, 2024 17:52
@filmaj filmaj self-assigned this Oct 2, 2024
Copy link

codecov bot commented Oct 2, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 91.74%. Comparing base (de54897) to head (63d93e0).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2059   +/-   ##
=======================================
  Coverage   91.74%   91.74%           
=======================================
  Files          38       38           
  Lines       10081    10081           
  Branches      631      631           
=======================================
  Hits         9249     9249           
  Misses        820      820           
  Partials       12       12           
Flag Coverage Δ
cli-hooks 95.23% <ø> (ø)
cli-test 95.69% <ø> (ø)
oauth 77.39% <ø> (ø)
socket-mode 58.22% <50.00%> (ø)
web-api 96.89% <ø> (ø)
webhook 96.65% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Copy link
Member

@zimeg zimeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! And this works with excitement! TBH it didn't even cross my mind that the message could be processed twice 😭

Thanks so much for both a deep dive and fast fix 🙏

Comment on lines +269 to +270
client.on('message', spy);
client.emit('ws_message', message, false /* isBinary */);
Copy link
Member

@zimeg zimeg Oct 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow! 😳 What a find!! 🔍 ✨

Edit: Argh should've included the surrounding spy for context but I cannot edit the lines commented on 😐

@filmaj filmaj merged commit 9d2fa58 into main Oct 2, 2024
29 of 30 checks passed
@filmaj filmaj deleted the socket-mode-double-message branch October 2, 2024 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented pkg:socket-mode applies to `@slack/socket-mode` semver:patch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parsing incoming WebSocket message fails with a SyntaxError from invalid JSON
2 participants