Unexpected closure of websocket connection

Hi there,
I m using aiohttp library for connecting to Twitch websocket server, just start my experience with VPS server, and now my script (regular chat-bot) is running 24/7, but before I ran it locally on the machine for about 6-8 hours
After i switched to VPS there is one thing that worries me, here is parts of my log (a bit formatted so you can understand better)

Start of session

WSMessage(type=<WSMsgType.TEXT: 1>, data=‘{“metadata”:{“message_id”:“…”,“message_type”:“session_welcome”,“message_timestamp”:“2025-03-21T06:18:41.460199337Z”},“payload”:{“session”:{“id”:“…”,“status”:“connected”,“connected_at”:“2025-03-21T06:18:41.455584904Z”,“keepalive_timeout_seconds”:10,“reconnect_url”:null,“recovery_url”:null}}}’, extra=‘’)

Reconnect

WSMessage(type=<WSMsgType.TEXT: 1>, data=‘{“metadata”:{“message_id”:“…”,“message_type”:“session_reconnect”,“message_timestamp”:“2025-03-21T17:09:47.848106944Z”},“payload”:{“session”:{“id”:“…”,“status”:“reconnecting”,“connected_at”:“2025-03-21T06:18:41.455584904Z”,“keepalive_timeout_seconds”:null,“reconnect_url”:“…”,“recovery_url”:null}}}’, extra=‘’)
WSMessage(type=<WSMsgType.TEXT: 1>, data=‘{“metadata”:{“message_id”:“…”,“message_type”:“session_welcome”,“message_timestamp”:“2025-03-21T17:09:47.905234804Z”},“payload”:{“session”:{“id”:“…”,“status”:“connected”,“connected_at”:“2025-03-21T06:18:41Z”,“keepalive_timeout_seconds”:10,“reconnect_url”:null,“recovery_url”:null}}}’, extra=‘’)

Seems all is good, cuz i keep receiving messages, so i believe my code is fine, but the next day I received a message about the connection being closed, without any data or extra info

Connection closed

WSMessage(type=<WSMsgType.TEXT: 1>, data=‘{“metadata”:{“message_id”:“…”,“message_type”:“session_keepalive”,“message_timestamp”:“2025-03-22T01:13:21.400880887Z”},“payload”:{}}’, extra=‘’)
WSMessage(type=<WSMsgType.TEXT: 1>, data=‘{“metadata”:{“message_id”:“…”,“message_type”:“session_keepalive”,“message_timestamp”:“2025-03-22T01:13:31.400779272Z”},“payload”:{}}’, extra=‘’)
WSMessage(type=<WSMsgType.CLOSED: 257>, data=None, extra=None)
2025-03-22 01:13:35.101:WARNING : WSMessage(type=<WSMsgType.CLOSED: 257>, data=None, extra=None)

So, now I’m trying to understand the reasons for what happened, on which side is problem
Should i look for something specific, or this is just unstable network and i should reconnect when im getting this kind of trouble?

potentially

What was the websocket close code? Doesn’t seem to have been logged in your log.

Thank you for your fast response

Yeah, as i can see, i doesnt log close code, i ll fix this and return with details, if it will happen again

I suspect a 1006 abnormal closure which is a catch all for network schnanigans.

If it starts with a 1 then it’s a socket issue

If it starts with a 4 then it’s a twitch sent code.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.