slack-go/slack

SocketmodeHandler RunEventLoopContext method

lololozhkin opened this issue · 4 comments

Description

socketmodeHandler.RunEventLoop() function doesn't allow to provide context for cancellation, so I couldn't find any way to gracefully stop event handling from websocket.. One of the ways is to close handler.Client.Events channel, but it is dangerous due to possible panics in channel writes, it also not the only channel in this struct, and it is not guaranteed that websocket connection will be gracefully shut down :(

In other abstractions library has methods like RunContext() and I think it is good idea to write such a method for socketmodeHandler.

I could do it myself, but I aware of not propper shutting down the client (I coudn't find any close(client.Events) channel)

It looks like that logic is somewhat in place but context.TODO() is used instead of exposing a context to be passed. I'm also experiencing this issue and would be willing to put up a PR for the fix.

https://github.com/slack-go/slack/blob/master/socketmode/socket_mode_managed_conn.go#L33

Being able to pass a cancellable context is exactly what I am looking for. I would highly appreciate any effort in implementing this.

Made pr with requested functionality, waiting for pull request to be approved.

Resolved by #1169