Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random websocket connection closed errors #171

Closed
1 task
mazerab opened this issue Mar 3, 2017 · 10 comments
Closed
1 task

Random websocket connection closed errors #171

mazerab opened this issue Mar 3, 2017 · 10 comments

Comments

@mazerab
Copy link

mazerab commented Mar 3, 2017

Description

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.

Reproducible in:

  • This is reproducible in the sample project.
    python-slackclient version: 0.3.0
    Python Version: 2.7
    OS Version: Windows Server 2012 R2

Steps to reproduce:

  1. Run the script
  2. Wait for socket to close, on try / except reconnect through slack_client.rtm_connect()

Expected result:

Socket never closes

Actual result:

Socket closes randomly causing script to have to re-connect multiple times, leading to script becoming unresponsive eventually

Attachments:

Sample Python script
sample.py.zip

@mazerab
Copy link
Author

mazerab commented Mar 13, 2017

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.

@harlowja
Copy link
Contributor

harlowja commented Apr 3, 2017

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

@harlowja
Copy link
Contributor

harlowja commented Apr 3, 2017

I also have reconnect logic as well (that will sleep X amount of time, then reconnect, and repeat...)

@anianruoss
Copy link

I experienced the same problem.

@aoberoi
Copy link
Contributor

aoberoi commented Jun 19, 2017

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)

@aoberoi
Copy link
Contributor

aoberoi commented Jun 26, 2017

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.

@kootenpv
Copy link

In my case:


# works
websocket-client==0.54.0

# does not work
websocket-client==0.55.0

@winsimi
Copy link

winsimi commented Feb 25, 2019

Same for me ...

0.54.0 working,
0.55.0 not working.

@ti-guru
Copy link

ti-guru commented Mar 1, 2019

Same issue here. Downgrading websocket-client from 0.55 to 0.54 solved the problem.

@RodneyU215
Copy link
Contributor

Thanks for everyone reporting the issue! I've addressed this with a patch for now: #387

I'm going to continue digging into solving the root cause in websocket-client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants