Skip to content

When internet is down, library will eventually fail to connect without notifying client #318

Description

@adhawkins

I have a chat bot based on pytwitchapi. My internet was down for a few hours recently, and it was only when I happened to notice the bot wasn't working when I realised that it had failed to connect to the Twitch API (understandably) and gave up attempting to reconnect:

Jul 17 01:55:13 xcp-dev python[808]: Reached timeout for websocket receive, will attempt a reconnect
Jul 17 01:55:16 xcp-dev python[808]: connection attempt failed, retry in 0s...
Jul 17 01:55:20 xcp-dev python[808]: connection attempt failed, retry in 1s...
Jul 17 01:55:21 xcp-dev python[808]: connection attempt failed, retry in 2s...
Jul 17 01:55:23 xcp-dev python[808]: connection attempt failed, retry in 4s...
Jul 17 01:55:27 xcp-dev python[808]: connection attempt failed, retry in 8s...
Jul 17 01:55:39 xcp-dev python[808]: connection attempt failed, retry in 16s...
Jul 17 01:55:58 xcp-dev python[808]: connection attempt failed, retry in 32s...
Jul 17 01:56:33 xcp-dev python[808]: connection attempt failed, retry in 64s...
Jul 17 01:56:50 xcp-dev python[808]: Reached timeout for websocket receive, will attempt a reconnect
Jul 17 01:56:53 xcp-dev python[808]: connection attempt failed, retry in 0s...
Jul 17 01:56:57 xcp-dev python[808]: connection attempt failed, retry in 1s...
Jul 17 01:56:58 xcp-dev python[808]: connection attempt failed, retry in 2s...
Jul 17 01:57:00 xcp-dev python[808]: connection attempt failed, retry in 4s...
Jul 17 01:57:04 xcp-dev python[808]: connection attempt failed, retry in 8s...
Jul 17 01:57:15 xcp-dev python[808]: connection attempt failed, retry in 16s...
Jul 17 01:57:35 xcp-dev python[808]: connection attempt failed, retry in 32s...
Jul 17 01:57:40 xcp-dev python[808]: connection attempt failed, retry in 128s...
Jul 17 01:58:10 xcp-dev python[808]: connection attempt failed, retry in 64s...
Jul 17 01:59:17 xcp-dev python[808]: connection attempt failed, retry in 128s...
Jul 17 01:59:48 xcp-dev python[808]: Connection to chat websocket lost and unable to reestablish connection!
Jul 17 01:59:48 xcp-dev python[808]: Traceback (most recent call last):
Jul 17 01:59:48 xcp-dev python[808]:   File "/home/andy/software/pytwitchchatlogger/venv/lib/python3.11/site-packages/aiohttp/client_ws.py", line 244, in receive
Jul 17 01:59:48 xcp-dev python[808]:     msg = await self._reader.read()
Jul 17 01:59:48 xcp-dev python[808]:           ^^^^^^^^^^^^^^^^^^^^^^^^^
Jul 17 01:59:48 xcp-dev python[808]:   File "/home/andy/software/pytwitchchatlogger/venv/lib/python3.11/site-packages/aiohttp/streams.py", line 681, in read
Jul 17 01:59:48 xcp-dev python[808]:     return await super().read()
Jul 17 01:59:48 xcp-dev python[808]:            ^^^^^^^^^^^^^^^^^^^^
Jul 17 01:59:48 xcp-dev python[808]:   File "/home/andy/software/pytwitchchatlogger/venv/lib/python3.11/site-packages/aiohttp/streams.py", line 640, in read
Jul 17 01:59:48 xcp-dev python[808]:     await self._waiter
Jul 17 01:59:48 xcp-dev python[808]: asyncio.exceptions.CancelledError
Jul 17 01:59:48 xcp-dev python[808]: During handling of the above exception, another exception occurred:
Jul 17 01:59:48 xcp-dev python[808]: Traceback (most recent call last):
Jul 17 01:59:48 xcp-dev python[808]:   File "/home/andy/software/pytwitchchatlogger/venv/lib/python3.11/site-packages/twitchAPI/chat/__init__.py", line 913, in __task_receive
Jul 17 01:59:48 xcp-dev python[808]:     message = await self.__connection.receive(timeout=receive_timeout)
Jul 17 01:59:48 xcp-dev python[808]:               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jul 17 01:59:48 xcp-dev python[808]:   File "/home/andy/software/pytwitchchatlogger/venv/lib/python3.11/site-packages/aiohttp/client_ws.py", line 243, in receive
Jul 17 01:59:48 xcp-dev python[808]:     async with async_timeout.timeout(timeout or self._receive_timeout):
Jul 17 01:59:48 xcp-dev python[808]:   File "/usr/lib/python3.11/asyncio/timeouts.py", line 98, in __aexit__
Jul 17 01:59:48 xcp-dev python[808]:     raise TimeoutError
Jul 17 01:59:48 xcp-dev python[808]: TimeoutError
Jul 17 01:59:48 xcp-dev python[808]: During handling of the above exception, another exception occurred:
Jul 17 01:59:48 xcp-dev python[808]: Traceback (most recent call last):
Jul 17 01:59:48 xcp-dev python[808]:   File "/home/andy/software/pytwitchchatlogger/venv/lib/python3.11/site-packages/twitchAPI/chat/__init__.py", line 918, in __task_receive
Jul 17 01:59:48 xcp-dev python[808]:     await self._handle_base_reconnect()
Jul 17 01:59:48 xcp-dev python[808]:   File "/home/andy/software/pytwitchchatlogger/venv/lib/python3.11/site-packages/twitchAPI/chat/__init__.py", line 956, in _handle_base_reconnect
Jul 17 01:59:48 xcp-dev python[808]:     await self.__connect(is_startup=False)
Jul 17 01:59:48 xcp-dev python[808]:   File "/home/andy/software/pytwitchchatlogger/venv/lib/python3.11/site-packages/twitchAPI/chat/__init__.py", line 866, in __connect
Jul 17 01:59:48 xcp-dev python[808]:     raise TwitchBackendException('can\'t connect')
Jul 17 01:59:48 xcp-dev python[808]: twitchAPI.type.TwitchBackendException: can't connect
Jul 17 02:01:25 xcp-dev python[808]: Connection to chat websocket lost and unable to reestablish connection!
Jul 17 02:01:25 xcp-dev python[808]: Traceback (most recent call last):
Jul 17 02:01:25 xcp-dev python[808]:   File "/home/andy/software/pytwitchchatlogger/venv/lib/python3.11/site-packages/aiohttp/client_ws.py", line 244, in receive
Jul 17 02:01:25 xcp-dev python[808]:     msg = await self._reader.read()
Jul 17 02:01:25 xcp-dev python[808]:           ^^^^^^^^^^^^^^^^^^^^^^^^^
Jul 17 02:01:25 xcp-dev python[808]:   File "/home/andy/software/pytwitchchatlogger/venv/lib/python3.11/site-packages/aiohttp/streams.py", line 681, in read
Jul 17 02:01:25 xcp-dev python[808]:     return await super().read()
Jul 17 02:01:25 xcp-dev python[808]:            ^^^^^^^^^^^^^^^^^^^^
Jul 17 02:01:25 xcp-dev python[808]:   File "/home/andy/software/pytwitchchatlogger/venv/lib/python3.11/site-packages/aiohttp/streams.py", line 640, in read
Jul 17 02:01:25 xcp-dev python[808]:     await self._waiter
Jul 17 02:01:25 xcp-dev python[808]: asyncio.exceptions.CancelledError
Jul 17 02:01:25 xcp-dev python[808]: During handling of the above exception, another exception occurred:
Jul 17 02:01:25 xcp-dev python[808]: Traceback (most recent call last):
Jul 17 02:01:25 xcp-dev python[808]:   File "/home/andy/software/pytwitchchatlogger/venv/lib/python3.11/site-packages/twitchAPI/chat/__init__.py", line 913, in __task_receive
Jul 17 02:01:25 xcp-dev python[808]:     message = await self.__connection.receive(timeout=receive_timeout)
Jul 17 02:01:25 xcp-dev python[808]:               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jul 17 02:01:25 xcp-dev python[808]:   File "/home/andy/software/pytwitchchatlogger/venv/lib/python3.11/site-packages/aiohttp/client_ws.py", line 243, in receive
Jul 17 02:01:25 xcp-dev python[808]:     async with async_timeout.timeout(timeout or self._receive_timeout):
Jul 17 02:01:25 xcp-dev python[808]:   File "/usr/lib/python3.11/asyncio/timeouts.py", line 98, in __aexit__
Jul 17 02:01:25 xcp-dev python[808]:     raise TimeoutError
Jul 17 02:01:25 xcp-dev python[808]: TimeoutError
Jul 17 02:01:25 xcp-dev python[808]: During handling of the above exception, another exception occurred:
Jul 17 02:01:25 xcp-dev python[808]: Traceback (most recent call last):
Jul 17 02:01:25 xcp-dev python[808]:   File "/home/andy/software/pytwitchchatlogger/venv/lib/python3.11/site-packages/twitchAPI/chat/__init__.py", line 918, in __task_receive
Jul 17 02:01:25 xcp-dev python[808]:     await self._handle_base_reconnect()
Jul 17 02:01:25 xcp-dev python[808]:   File "/home/andy/software/pytwitchchatlogger/venv/lib/python3.11/site-packages/twitchAPI/chat/__init__.py", line 956, in _handle_base_reconnect
Jul 17 02:01:25 xcp-dev python[808]:     await self.__connect(is_startup=False)
Jul 17 02:01:25 xcp-dev python[808]:   File "/home/andy/software/pytwitchchatlogger/venv/lib/python3.11/site-packages/twitchAPI/chat/__init__.py", line 866, in __connect
Jul 17 02:01:25 xcp-dev python[808]:     raise TwitchBackendException('can\'t connect')
Jul 17 02:01:25 xcp-dev python[808]: twitchAPI.type.TwitchBackendException: can't connect
Jul 18 10:22:28 xcp-dev systemd[751]: Stopping pytwitchchatlogger.service...

There apparently isn't a way that this exception could be caught so that the client can tell the library to initiate a re-connect.

Posting here at Lena's request (from Discord)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions