Python-slack-sdk: RTM client stops listening after a while

Created on 23 Jun 2019  路  1Comment  路  Source: slackapi/python-slack-sdk

Description

After a random amount of time, the RTM stops listening to slack events. I can see asyncio errors in the console, however no errors are actually thrown.

Fatal read error on socket transport
protocol: <asyncio.sslproto.SSLProtocol object at 0x1045e4278>
transport: <_SelectorSocketTransport fd=10 read=polling write=<idle, bufsize=0>>
Traceback (most recent call last):
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/selector_events.py", line 801, in _read_ready__data_received
    data = self._sock.recv(self.max_size)
OSError: [Errno 65] No route to host

Not sure if this is a bug in asyncio, but anyway my RTM client stops listening to slack and becomes a zombie as no error is actually thrown. I also could not figure out how to read the log.

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.

Reproducible in:

slackclient version: 2

python version: 3.7

OS version(s): Mac OS X Mojave

Steps to reproduce:

  1. Start an RTM client with run_async=True
  2. Wait a few minutes
  3. The client stops listening to slack

Expected result:

RTM events are triggered by slack messages

Actual result:

Nothing happens when a message is sent, errors are shown in the log

Attachments:

A sample code that runs a loop in parallel to an RTM client which reproduces the issue:

import slack
import time
import asyncio
import concurrent
from datetime import datetime


@slack.RTMClient.run_on(event='message')
async def say_hello(**payload):
    data = payload['data']
    print(data.get('text'))


def sync_loop():
    while True:
        print("Hi there: ", datetime.now())
        time.sleep(5)


async def slack_main():
    executor = concurrent.futures.ThreadPoolExecutor(max_workers=1)
    loop = asyncio.get_event_loop()
    rtm_client = None
    try:
        rtm_client = slack.RTMClient(token='token', run_async=True, loop=loop, timeout=300, auto_reconnect=True)
        await asyncio.gather(
            loop.run_in_executor(executor, sync_loop),
            rtm_client.start()
        )
    except asyncio.TimeoutError:
        rtm_client.stop()
    except Exception as e:
        pass
        # Never gets here


if __name__ == "__main__":
    asyncio.run(slack_main())
2x bug

Most helpful comment

Hi @liorblob, This issue should now be fixed in v2.1.0 thanks to #453.

>All comments

Hi @liorblob, This issue should now be fixed in v2.1.0 thanks to #453.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

divyatman picture divyatman  路  4Comments

seratch picture seratch  路  3Comments

sofya-salmanova picture sofya-salmanova  路  5Comments

vv-grinko picture vv-grinko  路  3Comments

LMPK picture LMPK  路  3Comments