slackapi / node-slack-sdk

Slack Developer Kit for Node.js
https://slack.dev/node-slack-sdk
MIT License
3.27k stars 662 forks source link

Socket Mode Rewrite to Python(ish) Implementation #1781

Closed filmaj closed 5 months ago

filmaj commented 5 months ago

Socket Mode Rewrite

This PR ports, as much as possible, the Python implementation of the Socket Mode client to node.

I have been running a longevity test of an app, in production, on a busy workspace, using this PR since April 24th without issue (the app reconnects gracefully when Slack sends a disconnect message, which is what we expect).

Why?

The existing node socket-mode package uses finity, an old finite state machine configuration package. While it has served us well, it has been difficult to maintain, with tricky semantics. Additionally, the existing socket-mode implementation is almost a straight copy-paste of the rtm-api module, which is very old.

Breaking Changes

What's The Same?

Many of the developer-facing APIs have remained the same:

Internal Design Changes

IMO this leads to a nice separation of concerns.

Concerns / Questions / Request for Feedback

filmaj commented 5 months ago

Thanks for the reviews! I did see some CI failures with the integration tests, and I realized some of the sequencing of events / websocket behaviour in the test was not ideal and probably brittle on a weaker machines (like GitHub Actions). Running them once on my local machine tended to pass them, but if I ran the tests like this instead:

while npm run test:integration; do echo "OK"; done

.. after about 10 or so runs I could trigger a failure.

I made a change in the tests to make them more resilient (any event-based waiting promises should be created after start() completes, not after any timeouts; ensures the event loop has opportunity to execute a few iterations to ensure events get picked up properly by any waiters) and now they pass on both local and CI at a much higher rate.

Also confirming that the longevity test I had set up has been operating flawlessly for a week.

Merging this! Hooray! I will likely publish a 2.0 release of socket-mode soon!