After upgrading from Websocket-client 0.54.0 to 0.55.0 rtm_connect(), rtm_read() fails on the first call with the exception
websocket._exceptions.WebSocketConnectionClosedException: Connection is already closed.
x in one of the [ ])x in each of the [ ])Filling out the following details about bugs will help us solve your issue sooner.
slackclient version: 1.3.0
websocket-client: 0.55.0
python version: Tried 3.6.5, 3.7.2
OS version(s): macOs High Sierra, Ubuntu 18.04, Ubuntu 16.04
Run this simple script with your own app token:
from slackclient import SlackClient
import time
import logging
logging.basicConfig(level=logging.DEBUG)
sc = SlackClient("xoxb-...")
sc.rtm_connect()
while True:
print("reading...")
print(sc.rtm_read())
print("sleeping...")
time.sleep(0.1)
Script happily connects and runs
connecting...
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): slack.com:443
DEBUG:urllib3.connectionpool:https://slack.com:443 "POST /api/rtm.connect HTTP/1.1" 200 266
DEBUG:root:RTM connected
reading...
[]
sleeping...
reading...
[]
sleeping...
reading...
[]
sleeping...
reading...
[]
sleeping...
reading...
[{'type': 'hello'}]
sleeping...
reading...
[]
sleeping...
reading...
[]
sleeping...
connecting...
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): slack.com:443
DEBUG:urllib3.connectionpool:https://slack.com:443 "POST /api/rtm.connect HTTP/1.1" 200 265
DEBUG:root:RTM connected
reading...
DEBUG:root:RTM disconnected
Traceback (most recent call last):
File "/home/timah/test/python-slackclient/slackclient/server.py", line 278, in websocket_safe_read
data += "{0}\n".format(self.websocket.recv())
File "/home/timah/test/lib/python3.6/site-packages/websocket/_core.py", line 313, in recv
opcode, data = self.recv_data()
File "/home/timah/test/lib/python3.6/site-packages/websocket/_core.py", line 330, in recv_data
opcode, frame = self.recv_data_frame(control_frame)
File "/home/timah/test/lib/python3.6/site-packages/websocket/_core.py", line 343, in recv_data_frame
frame = self.recv_frame()
File "/home/timah/test/lib/python3.6/site-packages/websocket/_core.py", line 377, in recv_frame
return self.frame_buffer.recv_frame()
File "/home/timah/test/lib/python3.6/site-packages/websocket/_abnf.py", line 361, in recv_frame
self.recv_header()
File "/home/timah/test/lib/python3.6/site-packages/websocket/_abnf.py", line 309, in recv_header
header = self.recv_strict(2)
File "/home/timah/test/lib/python3.6/site-packages/websocket/_abnf.py", line 396, in recv_strict
bytes_ = self.recv(min(16384, shortage))
File "/home/timah/test/lib/python3.6/site-packages/websocket/_core.py", line 452, in _recv
return recv(self.sock, bufsize)
File "/home/timah/test/lib/python3.6/site-packages/websocket/_socket.py", line 112, in recv
"Connection is already closed.")
websocket._exceptions.WebSocketConnectionClosedException: Connection is already closed.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 13, in <module>
print(sc.rtm_read())
File "/home/timah/test/python-slackclient/slackclient/client.py", line 235, in rtm_read
json_data = self.server.websocket_safe_read()
File "/home/timah/test/python-slackclient/slackclient/server.py", line 296, in websocket_safe_read
"Unable to send due to closed RTM websocket"
slackclient.server.SlackConnectionError: Unable to send due to closed RTM websocket
Downgrade websocket-client to 0.54.0 and everything is happy again.
Logs, screenshots, screencast, sample project, funny gif, etc.
Might be this but I'm no ssl expert. https://github.com/websocket-client/websocket-client/pull/474
Happens here too.
In Windows 10, Python 3.7.1.
Started happenning for us today too. For now as a hotfix I think it would be best to add websocket version limit < 0.55.0 to setup.py.
Thanks @tahpee for reporting this issue! I believe the temporary hotfix that @messa suggested is a good idea for now. If anyone would like to push that PR I'll approve it, if not I'll work to get it in a little later today.
The workaround has been released. I'll continue digging into the recent changes on websocket-client to find the bug.
With the release of websocket-client v0.56.0 can this be closed and #387 be reverted? Testing with the sample testcase no longer fails with 0.56.0 installed.
Yeah, per https://github.com/websocket-client/websocket-client/pull/536 , this is now resolved.
I can PR against the https://github.com/slackapi/python-slackclient/tree/v1 branch if that helps?
As 1.3.1+ versions are free from this issue (by locking the dependency version), let me close this issue now.
Most helpful comment
With the release of websocket-client v0.56.0 can this be closed and #387 be reverted? Testing with the sample testcase no longer fails with 0.56.0 installed.