Python-slack-sdk: Websocket-client 0.55.0 breaks slackclient rtm_connect/rtm_read

Created on 26 Feb 2019  路  8Comments  路  Source: slackapi/python-slack-sdk

Description

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.

What type of issue is this? (place an x in one of the [ ])

  • [x] bug
  • [ ] enhancement (feature request)
  • [ ] question
  • [ ] documentation related
  • [ ] testing related
  • [ ] discussion

Requirements (place an x in each of the [ ])

  • [x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [x] I've read and agree to the Code of Conduct.
  • [x] I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

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

Steps to reproduce:

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)

Expected result:

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...

Actual result:

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

Workaround

Downgrade websocket-client to 0.54.0 and everything is happy again.

Attachments:

Logs, screenshots, screencast, sample project, funny gif, etc.

1x bug

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.

All 8 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tinoargentino picture tinoargentino  路  4Comments

Terrance picture Terrance  路  3Comments

kompotkot picture kompotkot  路  4Comments

schlegelp picture schlegelp  路  3Comments

sofya-salmanova picture sofya-salmanova  路  5Comments