When disconnected with code 1006, it doesn't resubscribe to the events upon reconnection and continues to be disconnected with code 4003.
At that time, I was testing Eventsub using the Bot class. While it was left connected, it seems the network was briefly disconnected, and it kept getting disconnected with code 4003.
Reproduction steps
1. Establishing a WebSocket connection.
2. Disconnecting the PC from the network.
3. We will restore the network connection shortly.
4. It keeps getting disconnected with code 4003.
Logs
[2024-08-31 01:33:00] [DEBUG] twitch.http: New session has been created.
[2024-08-31 01:33:01] [DEBUG] twitch.http: GET >> https://id.twitch.tv/oauth2/validate with None has returned status code 200
[2024-08-31 01:33:01] [DEBUG] twitch.http: GET << https://id.twitch.tv/oauth2/validate has received {****}
[2024-08-31 01:33:01] [DEBUG] twitch.http: Keep-alive task has been created.
[2024-08-31 01:33:01] [DEBUG] twitch.http: GET >> https://api.twitch.tv/helix/users?id=**** with None has returned status code 200
[2024-08-31 01:33:01] [DEBUG] twitch.http: GET << https://api.twitch.tv/helix/users?id=**** has received {****}
[2024-08-31 01:33:01] [DEBUG] twitch.http: GET >> https://api.twitch.tv/helix/channels?broadcaster_id=**** with None has returned status code 200
[2024-08-31 01:33:01] [DEBUG] twitch.http: GET << https://api.twitch.tv/helix/channels?broadcaster_id=**** has received {****}
[2024-08-31 01:33:01] [DEBUG] twitch.http: GET >> https://api.twitch.tv/helix/streams?user_id=****&type=all&first=20 with None has returned status code 200
[2024-08-31 01:33:01] [DEBUG] twitch.http: GET << https://api.twitch.tv/helix/streams?user_id=****&type=all&first=20 has received {'data': [], 'pagination': {}}
[2024-08-31 01:33:02] [DEBUG] twitch.gateway: Connected to WebSocket. Session ID: AgoQPaSX86H1TXOVZweYpjo8tBIGY2VsbC1h
[2024-08-31 01:33:02] [DEBUG] twitch.http: POST >> https://api.twitch.tv/helix/eventsub/subscriptions with None has returned status code 202
[2024-08-31 01:33:02] [DEBUG] twitch.http: POST << https://api.twitch.tv/helix/eventsub/subscriptions has received {'data': [{'id': '9cb70b6e-51d2-4a42-bd1d-d28e08e5a54d', 'status': 'enabled', 'type': 'stream.offline', 'version': '1', 'condition': {'broadcaster_user_id': '****'}, 'created_at': '2024-08-30T16:33:02.405963282Z', 'transport': {'method': 'websocket', 'session_id': 'AgoQPaSX86H1TXOVZweYpjo8tBIGY2VsbC1h', 'connected_at': '2024-08-30T16:33:02Z'}, 'cost': 0}], 'total': 86, 'max_total_cost': 10, 'total_cost': 0}
[2024-08-31 01:33:02] [DEBUG] twitch.http: POST >> https://api.twitch.tv/helix/eventsub/subscriptions with None has returned status code 202
[2024-08-31 01:33:02] [DEBUG] twitch.http: POST << https://api.twitch.tv/helix/eventsub/subscriptions has received {'data': [{'id': '0b3a4181-b842-43d0-8649-a1f42c926214', 'status': 'enabled', 'type': 'stream.online', 'version': '1', 'condition': {'broadcaster_user_id': '****'}, 'created_at': '2024-08-30T16:33:02.60242567Z', 'transport': {'method': 'websocket', 'session_id': 'AgoQPaSX86H1TXOVZweYpjo8tBIGY2VsbC1h', 'connected_at': '2024-08-30T16:33:02Z'}, 'cost': 0}], 'total': 86, 'max_total_cost': 10, 'total_cost': 0}
[2024-08-31 01:33:02] [DEBUG] twitch.http: POST >> https://api.twitch.tv/helix/eventsub/subscriptions with None has returned status code 202
[2024-08-31 01:33:02] [DEBUG] twitch.http: POST << https://api.twitch.tv/helix/eventsub/subscriptions has received {'data': [{'id': '42fb3220-e24b-4cc1-af39-3af9dca40c2a', 'status': 'enabled', 'type': 'channel.update', 'version': '2', 'condition': {'broadcaster_user_id': '****'}, 'created_at': '2024-08-30T16:33:02.778403667Z', 'transport': {'method': 'websocket', 'session_id': 'AgoQPaSX86H1TXOVZweYpjo8tBIGY2VsbC1h', 'connected_at': '2024-08-30T16:33:02Z'}, 'cost': 0}], 'total': 86, 'max_total_cost': 10, 'total_cost': 0}
[2024-08-31 01:33:03] [DEBUG] twitch.http: POST >> https://api.twitch.tv/helix/eventsub/subscriptions with None has returned status code 202
[2024-08-31 01:33:03] [DEBUG] twitch.http: POST << https://api.twitch.tv/helix/eventsub/subscriptions has received {'data': [{'id': '8e31890c-1cf5-4336-9a65-ae77081e20cf', 'status': 'enabled', 'type': 'user.update', 'version': '1', 'condition': {'user_id': '****'}, 'created_at': '2024-08-30T16:33:02.965229495Z', 'transport': {'method': 'websocket', 'session_id': 'AgoQPaSX86H1TXOVZweYpjo8tBIGY2VsbC1h', 'connected_at': '2024-08-30T16:33:02Z'}, 'cost': 0}], 'total': 86, 'max_total_cost': 10, 'total_cost': 0}
[2024-08-31 01:33:03] [DEBUG] twitch.http: POST >> https://api.twitch.tv/helix/eventsub/subscriptions with None has returned status code 202
[2024-08-31 01:33:03] [DEBUG] twitch.http: POST << https://api.twitch.tv/helix/eventsub/subscriptions has received {'data': [{'id': '7789472f-4630-4edc-b118-784ade4f008b', 'status': 'enabled', 'type': 'channel.chat.message', 'version': '1', 'condition': {'broadcaster_user_id': '****', 'user_id': '****'}, 'created_at': '2024-08-30T16:33:03.164661173Z', 'transport': {'method': 'websocket', 'session_id': 'AgoQPaSX86H1TXOVZweYpjo8tBIGY2VsbC1h', 'connected_at': '2024-08-30T16:33:02Z'}, 'cost': 0}], 'total': 86, 'max_total_cost': 10, 'total_cost': 0}
[2024-08-31 01:33:03] [DEBUG] twitch.client: Dispatching event ready
[2024-08-31 01:33:11] [DEBUG] twitch.gateway: Received WSMessage(type=<WSMsgType.CLOSED: 257>, data=None, extra=None)
[2024-08-31 01:33:11] [ERROR] twitch.client: WebSocket closed with 1006 close code. Attempting a reconnect in 8s
Traceback (most recent call last):
File "c:\****\Lib\site-packages\twitch\gateway.py", line 133, in poll_handle_dispatch
raise WebSocketClosure
twitch.gateway.WebSocketClosure
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "c:\****\Lib\site-packages\twitch\client.py", line 446, in connect
await self.ws.poll_handle_dispatch()
File "c:\****\Lib\site-packages\twitch\gateway.py", line 136, in poll_handle_dispatch
raise ConnectionClosed(self.socket, code=code) from exc
twitch.errors.ConnectionClosed: WebSocket closed with 1006 close code.
[2024-08-31 01:33:20] [DEBUG] twitch.gateway: Connected to WebSocket. Session ID: AgoQxs9NmZ5qRmGzEuF2MhdlGhIGY2VsbC1h
[2024-08-31 01:33:20] [DEBUG] twitch.client: Dispatching event ready
[2024-08-31 01:33:30] [DEBUG] twitch.gateway: Received WSMessage(type=<WSMsgType.CLOSE: 8>, data=4003, extra='connection unused')
[2024-08-31 01:33:30] [ERROR] twitch.client: WebSocket closed with 4003 close code. Attempting a reconnect in 8s
Traceback (most recent call last):
File "c:\****\Lib\site-packages\twitch\gateway.py", line 133, in poll_handle_dispatch
raise WebSocketClosure
twitch.gateway.WebSocketClosure
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "c:\****\Lib\site-packages\twitch\client.py", line 446, in connect
await self.ws.poll_handle_dispatch()
File "c:\****\Lib\site-packages\twitch\gateway.py", line 136, in poll_handle_dispatch
raise ConnectionClosed(self.socket, code=code) from exc
twitch.errors.ConnectionClosed: WebSocket closed with 4003 close code.
[2024-08-31 01:33:38] [DEBUG] twitch.gateway: Connected to WebSocket. Session ID: AgoQm79taUjjSVGTFdFDikqAZRIGY2VsbC1h
[2024-08-31 01:33:38] [DEBUG] twitch.client: Dispatching event ready
[2024-08-31 01:33:48] [DEBUG] twitch.gateway: Received WSMessage(type=<WSMsgType.CLOSE: 8>, data=4003, extra='connection unused')
[2024-08-31 01:33:48] [ERROR] twitch.client: WebSocket closed with 4003 close code. Attempting a reconnect in 8s
Traceback (most recent call last):
File "c:\****\Lib\site-packages\twitch\gateway.py", line 133, in poll_handle_dispatch
raise WebSocketClosure
twitch.gateway.WebSocketClosure
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "c:\****\Lib\site-packages\twitch\client.py", line 446, in connect
await self.ws.poll_handle_dispatch()
File "c:\****\Lib\site-packages\twitch\gateway.py", line 136, in poll_handle_dispatch
raise ConnectionClosed(self.socket, code=code) from exc
twitch.errors.ConnectionClosed: WebSocket closed with 4003 close code.
I didn't test on an unstable connection, but I see the issue now. When the WebSocket disconnects, it should reconnect and re-subscribe to all cached events. I'm working on a fix and appreciate your patience!
Description
When disconnected with code 1006, it doesn't resubscribe to the events upon reconnection and continues to be disconnected with code 4003.
At that time, I was testing Eventsub using the Bot class. While it was left connected, it seems the network was briefly disconnected, and it kept getting disconnected with code 4003.
Reproduction steps
Logs
OS
Windows