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

Periodic connection loss, not reconnecting #336

Closed
4 of 9 tasks
ses4j opened this issue Jul 18, 2018 · 9 comments
Closed
4 of 9 tasks

Periodic connection loss, not reconnecting #336

ses4j opened this issue Jul 18, 2018 · 9 comments
Assignees
Milestone

Comments

@ses4j
Copy link

ses4j commented Jul 18, 2018

Description

Similar to #118 and #101, we occasionally see a ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host crash. The exception is thrown out of lib/ssl.py, but the last spot in slackclient is https://github.com/slackapi/python-slackclient/blob/master/slackclient/server.py#L264.

Is there any reason autoreconnect reconnects after a WebSocketConnectionClosedException but not a ConnectionResetError? Maybe it could just be added?

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

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

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

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • 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: Sorry, not sure, but modern enough to have the same exact line number for the crashing lines. I'm reporting this secondhand.

python version: 3.5

OS version(s): Windows (I think)

Steps to reproduce:

  1. Connect with autoreconnect=True
  2. Wait, sometimes a few hours, sometimes a few days

Expected result:

Try to reconnect indefinitely if the connection bombs out.

Actual result:

Crash with ConnectionResetError.

Attachments:

@tobenary
Copy link

Same here but with Python 2.7.15
code run for

Traceback (most recent call last):
  File "C:/Users/ADMIN/PycharmProjects/sharefileslack/Sharefilebot_Phase4.py", line 225, in <module>
    tmp = sc.rtm_read()
  File "C:\Users\ADMIN\PycharmProjects\sharefileslack\venv\lib\site-packages\slackclient\client.py", line 125, in rtm_read
    json_data = self.server.websocket_safe_read()
  File "C:\Users\ADMIN\PycharmProjects\sharefileslack\venv\lib\site-packages\slackclient\server.py", line 264, in websocket_safe_read
    data += "{0}\n".format(self.websocket.recv())
  File "C:\Users\ADMIN\PycharmProjects\sharefileslack\venv\lib\site-packages\websocket\_core.py", line 300, in recv
    opcode, data = self.recv_data()
  File "C:\Users\ADMIN\PycharmProjects\sharefileslack\venv\lib\site-packages\websocket\_core.py", line 317, in recv_data
    opcode, frame = self.recv_data_frame(control_frame)
  File "C:\Users\ADMIN\PycharmProjects\sharefileslack\venv\lib\site-packages\websocket\_core.py", line 330, in recv_data_frame
    frame = self.recv_frame()
  File "C:\Users\ADMIN\PycharmProjects\sharefileslack\venv\lib\site-packages\websocket\_core.py", line 364, in recv_frame
    return self.frame_buffer.recv_frame()
  File "C:\Users\ADMIN\PycharmProjects\sharefileslack\venv\lib\site-packages\websocket\_abnf.py", line 361, in recv_frame
    self.recv_header()
  File "C:\Users\ADMIN\PycharmProjects\sharefileslack\venv\lib\site-packages\websocket\_abnf.py", line 309, in recv_header
    header = self.recv_strict(2)
  File "C:\Users\ADMIN\PycharmProjects\sharefileslack\venv\lib\site-packages\websocket\_abnf.py", line 396, in recv_strict
    bytes_ = self.recv(min(16384, shortage))
  File "C:\Users\ADMIN\PycharmProjects\sharefileslack\venv\lib\site-packages\websocket\_core.py", line 434, in _recv
    return recv(self.sock, bufsize)
  File "C:\Users\ADMIN\PycharmProjects\sharefileslack\venv\lib\site-packages\websocket\_socket.py", line 81, in recv
    bytes_ = sock.recv(bufsize)
  File "C:\Python27\Lib\ssl.py", line 772, in recv
    return self.read(buflen)
  File "C:\Python27\Lib\ssl.py", line 659, in read
    v = self._sslobj.read(len)
socket.error: [Errno 10054] An existing connection was forcibly closed by the remote host

And another one

Traceback (most recent call last):
  File "C:/Users/ADMIN/PycharmProjects/sharefileslack/Sharefilebot_Phase4.py", line 225, in <module>
    tmp = sc.rtm_read()
  File "C:\Users\ADMIN\PycharmProjects\sharefileslack\venv\lib\site-packages\slackclient\client.py", line 125, in rtm_read
    json_data = self.server.websocket_safe_read()
  File "C:\Users\ADMIN\PycharmProjects\sharefileslack\venv\lib\site-packages\slackclient\server.py", line 264, in websocket_safe_read
    data += "{0}\n".format(self.websocket.recv())
  File "C:\Users\ADMIN\PycharmProjects\sharefileslack\venv\lib\site-packages\websocket\_core.py", line 300, in recv
    opcode, data = self.recv_data()
  File "C:\Users\ADMIN\PycharmProjects\sharefileslack\venv\lib\site-packages\websocket\_core.py", line 317, in recv_data
    opcode, frame = self.recv_data_frame(control_frame)
  File "C:\Users\ADMIN\PycharmProjects\sharefileslack\venv\lib\site-packages\websocket\_core.py", line 330, in recv_data_frame
    frame = self.recv_frame()
  File "C:\Users\ADMIN\PycharmProjects\sharefileslack\venv\lib\site-packages\websocket\_core.py", line 364, in recv_frame
    return self.frame_buffer.recv_frame()
  File "C:\Users\ADMIN\PycharmProjects\sharefileslack\venv\lib\site-packages\websocket\_abnf.py", line 361, in recv_frame
    self.recv_header()
  File "C:\Users\ADMIN\PycharmProjects\sharefileslack\venv\lib\site-packages\websocket\_abnf.py", line 309, in recv_header
    header = self.recv_strict(2)
  File "C:\Users\ADMIN\PycharmProjects\sharefileslack\venv\lib\site-packages\websocket\_abnf.py", line 396, in recv_strict
    bytes_ = self.recv(min(16384, shortage))
  File "C:\Users\ADMIN\PycharmProjects\sharefileslack\venv\lib\site-packages\websocket\_core.py", line 434, in _recv
    return recv(self.sock, bufsize)
  File "C:\Users\ADMIN\PycharmProjects\sharefileslack\venv\lib\site-packages\websocket\_socket.py", line 81, in recv
    bytes_ = sock.recv(bufsize)
  File "C:\Python27\Lib\ssl.py", line 772, in recv
    return self.read(buflen)
  File "C:\Python27\Lib\ssl.py", line 659, in read
    v = self._sslobj.read(len)
socket.error: [Errno 10054] An existing connection was forcibly closed by the remote host
if sc.rtm_connect(auto_reconnect=True):
  while sc.server.connected is True:
        tmp = sc.rtm_read()
        if tmp:
            print tmp
            if 'subtype' in tmp[0]:
                time.sleep(1)
                continue
            if tmp[0]['type'] != 'message':
                time.sleep(1)
                continue
CODE....
  time.sleep(1)
else:
    print "Connection Failed"

@Roach
Copy link
Contributor

Roach commented Aug 15, 2018

@ses4j we can definitely add ConnectionResetError to the reconnect logic. We may not be able to get to this for a couple weeks, though.

We're always up merging for incoming PRs, and I feel like this is a pretty good first PR.

@jtsmith2
Copy link

We're always up merging for incoming PRs, and I feel like this is a pretty good first PR.

@Roach I could take this up if need be. My connection is resetting every night around midnight so my bot is missing things until I can restart my code each morning. Definitely willing to have this be my first PR to the project if you haven't already started working on it.

@Roach
Copy link
Contributor

Roach commented Oct 22, 2018

@jtsmith2 that would be awesome! We'd love the help.

Take a look through the contributing guide: https://github.com/slackapi/python-slackclient/blob/master/.github/contributing.md

@cmaliwal
Copy link

cmaliwal commented Oct 26, 2018

facing the same issue :

 File "/usr/local/lib/python3.5/site-packages/slackclient/client.py", line 235, in rtm_read
    json_data = self.server.websocket_safe_read()
  File "/usr/local/lib/python3.5/site-packages/slackclient/server.py", line 278, in websocket_safe_read
    data += "{0}\n".format(self.websocket.recv())
  File "/usr/local/lib/python3.5/site-packages/websocket/_core.py", line 302, in recv
    opcode, data = self.recv_data()
  File "/usr/local/lib/python3.5/site-packages/websocket/_core.py", line 319, in recv_data
    opcode, frame = self.recv_data_frame(control_frame)
  File "/usr/local/lib/python3.5/site-packages/websocket/_core.py", line 332, in recv_data_frame
    frame = self.recv_frame()
  File "/usr/local/lib/python3.5/site-packages/websocket/_core.py", line 366, in recv_frame
    return self.frame_buffer.recv_frame()
  File "/usr/local/lib/python3.5/site-packages/websocket/_abnf.py", line 361, in recv_frame
    self.recv_header()
  File "/usr/local/lib/python3.5/site-packages/websocket/_abnf.py", line 309, in recv_header
    header = self.recv_strict(2)
  File "/usr/local/lib/python3.5/site-packages/websocket/_abnf.py", line 396, in recv_strict
    bytes_ = self.recv(min(16384, shortage))
  File "/usr/local/lib/python3.5/site-packages/websocket/_core.py", line 441, in _recv
    return recv(self.sock, bufsize)
  File "/usr/local/lib/python3.5/site-packages/websocket/_socket.py", line 81, in recv
    bytes_ = sock.recv(bufsize)
  File "/usr/local/lib/python3.5/ssl.py", line 922, in recv
    return self.read(buflen)
  File "/usr/local/lib/python3.5/ssl.py", line 799, in read
    return self._sslobj.read(len, buffer)
  File "/usr/local/lib/python3.5/ssl.py", line 585, in read
    v = self._sslobj.read(len)
TimeoutError: [Errno 110] Operation timed out

@mattkrass
Copy link

Also experiencing this issue, is there any guesses when it might be addressed? I saw an open PR for it by @jtsmith2 but it doesn't seem to have any traction

@rranslam
Copy link

rranslam commented Feb 19, 2019

same here.

I see this with python 3.5.2, 3.5.6, 3.6.8 under pyenv on centos 7 and 3.5.2 in ubuntu 16.04. The more the server is load will cause to happen sooner. I have the bot auto reconnect ( i see the event [{'type': 'hello'}]) but after 5 of these it bails.

'''
Added auto-reconnect=True to address exceptions seen on busy servers
per slackclient/server.py#295 v1.3.0
https://slack.dev/python-slackclient/
https://api.slack.com/docs/rate-limits
'''

@seratch
Copy link
Member

seratch commented May 20, 2020

Does anyone encounter this issue with v2.x series? If not, please allow me to close this issue after waiting for responses for a few weeks. We're no longer actively working on the v1.x series. We appreciate your understanding. 🙇

@seratch seratch added this to the 1.x milestone May 20, 2020
@seratch
Copy link
Member

seratch commented Oct 27, 2020

As this project hasn't been actively supporting v1 for a while, please allow us to close this issue now.

The current latest stable version is v2.9.3. Here is the migration guide to v2 series. Also, we're going to release v3 soon: https://slack.dev/python-slack-sdk/

Both newer major versions should provide more stable implementation for this use case. It'd be appreciated if you could try newer versions. We hope the newer version resolves your issue.

@seratch seratch closed this as completed Oct 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants