I am running a Python script in a Windows server machine to use the Slack RTM API to listen on new incoming messages addressed to a bot. Based on the message, I write back to the Slack channel where the question was asked.
Unfortunately, the websocket used by RTM API is randomly getting closed, forcing me to come up with a workaround where I have to call slack_client.rtm_connect() in my except block to re-connect.
This is causing two issues:
I don't see a reason why the websocket is getting closed
After reconnecting multiple times, the Python script stops listening to messages directed to my bot, forcing me to restart the Python script manually.
Socket never closes
Socket closes randomly causing script to have to re-connect multiple times, leading to script becoming unresponsive eventually
Sample Python script
sample.py.zip
Hello, does anyone have any comments or suggestions for me to try? Thank you in advance for your time reviewing this new issue. It could relate to issue #118.
I think I also have seen this.
Traceback (most recent call last):
File "/opt/daddy/venv/lib/python2.7/site-packages/daddy/watchers/slack.py", line 152, in rtm_receiver
for event in slack_client.rtm_read():
File "/opt/daddy/venv/lib/python2.7/site-packages/slackclient/_client.py", line 123, in rtm_read
json_data = self.server.websocket_safe_read()
File "/opt/daddy/venv/lib/python2.7/site-packages/slackclient/_server.py", line 141, in websocket_safe_read
data += "{0}\n".format(self.websocket.recv())
File "/opt/daddy/venv/lib/python2.7/site-packages/websocket/_core.py", line 293, in recv
opcode, data = self.recv_data()
File "/opt/daddy/venv/lib/python2.7/site-packages/websocket/_core.py", line 310, in recv_data
opcode, frame = self.recv_data_frame(control_frame)
File "/opt/daddy/venv/lib/python2.7/site-packages/websocket/_core.py", line 323, in recv_data_frame
frame = self.recv_frame()
File "/opt/daddy/venv/lib/python2.7/site-packages/websocket/_core.py", line 357, in recv_frame
return self.frame_buffer.recv_frame()
File "/opt/daddy/venv/lib/python2.7/site-packages/websocket/_abnf.py", line 336, in recv_frame
self.recv_header()
File "/opt/daddy/venv/lib/python2.7/site-packages/websocket/_abnf.py", line 286, in recv_header
header = self.recv_strict(2)
File "/opt/daddy/venv/lib/python2.7/site-packages/websocket/_abnf.py", line 371, in recv_strict
bytes_ = self.recv(min(16384, shortage))
File "/opt/daddy/venv/lib/python2.7/site-packages/websocket/_core.py", line 427, in _recv
return recv(self.sock, bufsize)
File "/opt/daddy/venv/lib/python2.7/site-packages/websocket/_socket.py", line 93, in recv
"Connection is already closed.")
WebSocketConnectionClosedException: Connection is already closed.
# pip freeze | grep slack
slackclient==1.0.5
# pip freeze | grep web
websocket-client==0.40.0
I also have reconnect logic as well (that will sleep X amount of time, then reconnect, and repeat...)
I experienced the same problem.
Sorry for the long discussion without involvement from the maintainers. I just want to let you all know that we are investigating this issue (and the possibly related ones #118 #127)
this indeed seems like a duplicate of #118, which has a bit more data about the problem. I'm going to close this issue as a dup, but if you feel like there's something unique going on here that we should know about, feel free to comment.
In my case:
# works
websocket-client==0.54.0
# does not work
websocket-client==0.55.0
Same for me ...
0.54.0 working,
0.55.0 not working.
Same issue here. Downgrading websocket-client from 0.55 to 0.54 solved the problem.
Thanks for everyone reporting the issue! I've addressed this with a patch for now: https://github.com/slackapi/python-slackclient/pull/387
I'm going to continue digging into solving the root cause in websocket-client.
Most helpful comment
Same for me ...
0.54.0 working,
0.55.0 not working.