axi0m / skynet-bot

A bot for use in Slack - Helpful admin bot
MIT License
1 stars 0 forks source link

🐛 Ctrl+C signals not handled properly #13

Open axi0m opened 4 years ago

axi0m commented 4 years ago

The current version of the slack-bot doesn't handle Ctrl+C KeyboardInterrupts nor any other signals. There is a Python standard library called signal that may be useful to help.

axi0m commented 4 years ago

Unfortunately this is an upstream issue with aiohttp or asyncio, which slack client relies on. https://github.com/aio-libs/aiohttp/issues/3535

I've tested signal handling code per the following links and it works just fine https://pymotw.com/3/signal/ https://docs.python.org/3/library/signal.html https://keyboardinterrupt.org/catching-a-keyboardinterrupt-signal/

...but when using slack client it doesn't and hangs with the following error.

SSL error in data received
protocol: <asyncio.sslproto.SSLProtocol object at 0xb5965e10>
transport: <_SelectorSocketTransport fd=7 read=polling write=<idle, bufsize=0>>
Traceback (most recent call last):
  File "/home/axi0m/.pyenv/versions/3.7.3/lib/python3.7/asyncio/sslproto.py", line 526, in data_received
    ssldata, appdata = self._sslpipe.feed_ssldata(data)
  File "/home/axi0m/.pyenv/versions/3.7.3/lib/python3.7/asyncio/sslproto.py", line 207, in feed_ssldata
    self._sslobj.unwrap()
  File "/home/axi0m/.pyenv/versions/3.7.3/lib/python3.7/ssl.py", line 767, in unwrap
    return self._sslobj.shutdown()
ssl.SSLError: [SSL: KRB5_S_INIT] application data after close notify (_ssl.c:2609

At this point workaround is to run kill -9 <PID> when trying to stop the process from the host OS.