Frequent disconnects
I've recently noticed an increase of situations where my bot basically just gets disconnected... or at least stops receiving events from slack.
Sometimes logging would indicate that slack is sending goodbye message, but other times... it acts like its still connected, but all the notifications for everything just stop getting received.
I added a handler for goodbye message to at least bubble it up and let bots subscribe in a local fork, but still see places where its acting like connection is no longer connected, but no errors or anything.
Wondering if there is a way to detect if socket is disconnected and have it reconnect or something.
I have also been experiencing this more recently using the RTM api. To work around it, we have built the ping/pong functionality outlined here https://api.slack.com/rtm, on top of the SlackAPI's SendPing and OnPongReceived methods. If we don't receive a Pong in 20s after a Ping, we assume the connection is dead and attempt a re-connect, even if the SlackAPI is reporting IsConnected=true.
It seems to work, but I wonder if this Ping/Pong functionality should be built into the client natively or was it a design decision to not include it and instead expose all the tools needed to build it as needed?
The node-js package seems to have it built in https://github.com/slackapi/node-slack-sdk/blob/master/packages/rtm-api/src/KeepAlive.ts
I'd be willing to take a shot at building it if the maintainers think it's a worthy addition.
there are a few problems I found... one slack sends "bye" command quite a bit... and clients should be expected to handle that.
Additionally sometimes we dont get a bye, but the underlying websocket connection just gets closed.
I made changes to a local copy of the library that are changes that probably dont meet contributor requirements, but was able to do the following....
Implement command bye and surface it to the client, as well as implement an event on the client that surfaces when the underlying socket connection gets closed.
Then I simply call connect again... and do my best to synchronize access to new client connection creation. (you can actually create handlers that fire over and over and over... number of times its reconnected)
These changes have all but fixed my connection problems.
I'm swamped at the moment, but I'll see if I can't clean up the changes and provide better mechanism to handle the reconnect... and submit a pull request.