We observed intermittent disconnects when using the synchronous socketio.Client over WSS in a long-running
python process.
The connection was established successfully and Engine.IO ping/pong was working normally. However, after
running for some time, the sync client disconnected unexpectedly.
After instrumenting the stack, we found that the underlying TLS socket read returned an empty byte string:
ssl.SSLSocket.read(...) -> b""
Then websocket-client treated the connection as closed and raised:
WebSocketConnectionClosedException("Connection to remote host was lost.")
On the server side, this appeared as an abnormal WebSocket close:
close code: 1006
We also reproduced the issue with a minimal TLS Socket.IO setup outside of our business application:
socketio.AsyncServer + aiohttp server
socketio.Client sync client over wss://
The same setup became stable after changing only the client to:
socketio.AsyncClient + aiohttp
Our original sync client stack was:
socketio.Client
-> python-engineio sync Client
-> websocket-client
-> ssl.SSLSocket.read/recv
The stable stack is:
socketio.AsyncClient
-> python-engineio AsyncClient
-> aiohttp WebSocket client
Environment:
- Python: 3.10.11
- python-socketio: 5.16.1
- python-engineio: 4.13.1
- websocket-client: 1.9.0
- aiohttp: 3.12.15
- Transport: WSS
My questions are:
- Is this a known limitation or edge case of the sync client WSS stack?
- Are there recommended settings for long-running WSS connections with socketio.Client?
- Should long-running WSS clients prefer AsyncClient + aiohttp?
This report is mainly to share the debugging result and help others who may see intermittent WSS
disconnects with the sync client.
We observed intermittent disconnects when using the synchronous socketio.Client over WSS in a long-running
python process.
The connection was established successfully and Engine.IO ping/pong was working normally. However, after
running for some time, the sync client disconnected unexpectedly.
After instrumenting the stack, we found that the underlying TLS socket read returned an empty byte string:
ssl.SSLSocket.read(...) -> b""
Then websocket-client treated the connection as closed and raised:
WebSocketConnectionClosedException("Connection to remote host was lost.")
On the server side, this appeared as an abnormal WebSocket close:
close code: 1006
We also reproduced the issue with a minimal TLS Socket.IO setup outside of our business application:
socketio.AsyncServer + aiohttp server
socketio.Client sync client over wss://
The same setup became stable after changing only the client to:
socketio.AsyncClient + aiohttp
Our original sync client stack was:
socketio.Client
-> python-engineio sync Client
-> websocket-client
-> ssl.SSLSocket.read/recv
The stable stack is:
socketio.AsyncClient
-> python-engineio AsyncClient
-> aiohttp WebSocket client
Environment:
My questions are:
This report is mainly to share the debugging result and help others who may see intermittent WSS
disconnects with the sync client.