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

core: Add suport for keepalive messages #79

Merged
merged 1 commit into from Sep 3, 2018

Conversation

preludedrew
Copy link
Contributor

  • This patch is in response to Connection is closing every few days #54

    The websocket connection in slackclient seems to be getting dropped from the
    server side, with little to no indication as to why. Slack supports a ping/pong
    keep alive, and this implements it with slack machine.

 * This patch is in response to DonDebonair#54

   The websocket connection in slackclient seems to be getting dropped from the
   server side, with little to no indication as to why. Slack supports a ping/pong
   keep alive, and this implements it with slack machine.
@preludedrew
Copy link
Contributor Author

hmm, so I'm getting an exception with this patch.

[2018-08-15 21:45:56][DEBUG] machine.core core.py:_keepalive:184 | Client Ping!
[2018-08-15 21:45:56][DEBUG] machine.dispatch dispatch.py:handle_event:46 | Server Pong!
[2018-08-15 22:05:56][DEBUG] machine.core core.py:_keepalive:184 | Client Ping!
[2018-08-15 22:05:56][DEBUG] machine.dispatch dispatch.py:handle_event:46 | Server Pong!
Traceback (most recent call last):
  File "/usr/local/bin/slack-machine", line 11, in <module>
[2018-08-15 22:25:56][DEBUG] machine.core core.py:_keepalive:184 | Client Ping!
    sys.exit(main())
  File "/usr/local/lib/python3.5/dist-packages/machine/bin/run.py", line 14, in main
    bot.run()
  File "/usr/local/lib/python3.5/dist-packages/machine/core.py", line 214, in run
    self._dispatcher.start()
  File "/usr/local/lib/python3.5/dist-packages/machine/dispatch.py", line 23, in start
    for event in self._client.rtm_read():
  File "/usr/local/lib/python3.5/dist-packages/slackclient/client.py", line 125, in rtm_read
    json_data = self.server.websocket_safe_read()
  File "/usr/local/lib/python3.5/dist-packages/slackclient/server.py", line 264, in websocket_safe_read
    data += "{0}\n".format(self.websocket.recv())
  File "/usr/local/lib/python3.5/dist-packages/websocket/_core.py", line 300, in recv
    opcode, data = self.recv_data()
  File "/usr/local/lib/python3.5/dist-packages/websocket/_core.py", line 317, in recv_data
    opcode, frame = self.recv_data_frame(control_frame)
  File "/usr/local/lib/python3.5/dist-packages/websocket/_core.py", line 330, in recv_data_frame
    frame = self.recv_frame()
  File "/usr/local/lib/python3.5/dist-packages/websocket/_core.py", line 364, in recv_frame
    return self.frame_buffer.recv_frame()
  File "/usr/local/lib/python3.5/dist-packages/websocket/_abnf.py", line 361, in recv_frame
    self.recv_header()
  File "/usr/local/lib/python3.5/dist-packages/websocket/_abnf.py", line 309, in recv_header
    header = self.recv_strict(2)
  File "/usr/local/lib/python3.5/dist-packages/websocket/_abnf.py", line 396, in recv_strict
    bytes_ = self.recv(min(16384, shortage))
  File "/usr/local/lib/python3.5/dist-packages/websocket/_core.py", line 434, in _recv
    return recv(self.sock, bufsize)
  File "/usr/local/lib/python3.5/dist-packages/websocket/_socket.py", line 81, in recv
    bytes_ = sock.recv(bufsize)
  File "/usr/lib/python3.5/ssl.py", line 914, in recv
    return self.read(buflen)
  File "/usr/lib/python3.5/ssl.py", line 791, in read
    return self._sslobj.read(len, buffer)
  File "/usr/lib/python3.5/ssl.py", line 577, in read
    v = self._sslobj.read(len)
BlockingIOError: [Errno 11] Resource temporarily unavailable

Not sure where to start debugging this, since websocket is not included in slack machine, but in the slackclient module. One thing that is interesting, is running an strace on the pid, results in no error... So this is odd.

@DonDebonair
Copy link
Owner

You probably shouldn't use Python's _thread library. It's better to use the higher-level threading module, which does some house-keeping under the hood for you. I'm not saying it's related, but it doesn't hurt switching.

I'll have time to try the patch out this weekend.

@DonDebonair DonDebonair merged commit 5ab2743 into DonDebonair:master Sep 3, 2018
@DonDebonair
Copy link
Owner

Hey @preludedrew, I finally had time to look at some long-standing issues and PRs. I managed to fix yours as well. It's been merged and I will soon cut a new release for PyPI

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

Successfully merging this pull request may close these issues.

None yet

2 participants