Skip to content

RTM client stops listening after a while #458

@liorblob

Description

@liorblob

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 [ ])

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

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())

Metadata

Metadata

Assignees

No one assigned

    Labels

    Version: 2xbugM-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions