fix: add WebSocket heartbeat to prevent code=1006 disconnections#709
fix: add WebSocket heartbeat to prevent code=1006 disconnections#709livepeer-tessa wants to merge 1 commit intomainfrom
Conversation
Without a heartbeat, aiohttp does not send WebSocket ping frames, so NAT gateways, proxies, and firewalls can silently drop idle TCP connections. This manifests as code=1006 (abnormal closure / no close frame) after 10-30 minutes of use. Set heartbeat=30.0 on ws_connect so aiohttp sends a ping frame every 30 seconds, keeping the connection alive through middleboxes. Fixes #707 Signed-off-by: livepeer-robot <robot@livepeer.org>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Comment Tip CodeRabbit can scan for known vulnerabilities in your dependencies using OSV Scanner.OSV Scanner will automatically detect and report security vulnerabilities in your project's dependencies. No additional configuration is required. |
🚀 fal.ai Preview Deployment
TestingConnect to this preview deployment by running this on your branch: 🧪 E2E tests will run automatically against this deployment. |
✅ E2E Tests passed
Test ArtifactsCheck the workflow run for screenshots. |
Problem
Closes #707
Users experience abrupt cloud WebSocket disconnections (code=1006, reason=None) after 10-30+ minutes of use. Code 1006 means "abnormal closure" — the TCP connection was dropped without a WebSocket close frame.
Looking at the log from #707:
15:50:4916:05:5716:15:59(~10 min into active use)Root Cause
aiohttp.ws_connecthas noheartbeatset, so it never sends WebSocket ping frames. NAT gateways, proxies, and firewalls commonly drop TCP connections that appear idle (no traffic for some period). When the connection is dropped silently at the TCP level, there's no WebSocket close frame — hence code=1006 withreason=None.This is a well-known aiohttp pattern: without
heartbeat, long-running WebSocket connections die through middleboxes.Fix
Add
heartbeat=30.0tows_connect. This causes aiohttp to send a WebSocket ping frame every 30 seconds, which:Change
One line. The
heartbeatparameter is built into aiohttp and has no dependencies.