Skip to content

Intermittent WSS disconnects with sync socketio.Client; AsyncClient with aiohttp remains stable #1577

@yang7776

Description

@yang7776

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:

  1. Is this a known limitation or edge case of the sync client WSS stack?
  2. Are there recommended settings for long-running WSS connections with socketio.Client?
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions