-
-
Notifications
You must be signed in to change notification settings - Fork 586
Description
Hi there,
I am building a WebSocket client in Python (using websockets.asyncio) that consumes a continuous real-time telemetry stream from a third-party server. My goal is to keep this connection alive permanently (24/7).
However, I am experiencing periodic, seemingly random disconnections. Sometimes they happen exactly 24 hours apart, and other times there is no clear pattern. Crucially, these drops occur regardless of data traffic—they happen both during active, heavy data exchange and when the connection is completely idle.
The most common error I get is a clean closure initiated by the server:
websockets.exceptions.ConnectionClosedOK: received 1000 (OK); then sent 1000 (OK)
Other times, I receive an abnormal closure:
websockets.exceptions.ConnectionClosedError: code = 1006 (connection closed abnormally [internal])
Current Setup
To prevent firewalls and load balancers from killing the connection due to inactivity, I have configured the client with:
ping_interval=30
ping_timeout=60
I also have an exponential backoff loop in my main process (using a while True with asyncio.sleep) to catch these exceptions and reconnect automatically.
Since I am strictly a client and have no control over the third-party server's infrastructure:
Do you have any insights on what typically causes these periodic 1000 and 1006 closures even when there is an active flow of data and pings?
Is there a specific strategy, internal configuration, or architectural pattern you highly recommend when using this library to build a resilient, long-lived 24/7 client?
Thank you in advance for your time and guidance!
Looking forward to your feedback.
Daniel.