Skip to content

fix: keep idle WebSocket connections open through proxies - #1217

Merged
Apollon77 merged 2 commits into
mainfrom
fix/ws-keepalive
Oct 25, 2026
Merged

Apollon77 merged 2 commits into
mainfrom
fix/ws-keepalive

Conversation

@Apollon77

Copy link
Copy Markdown
Collaborator

Addresses #1213.

Nothing sent traffic on an idle WebSocket connection. Browsers never send WebSocket pings themselves, and the server did not send any either. A relay that closes idle connections, such as Home Assistant Cloud remote access, therefore dropped the dashboard every 1–2.5 minutes. The Home Assistant frontend stays connected over the same path because its server pings every 55 s. Supervisor and Core ingress pass ping/pong frames through.

  • The server pings each client of its WebSocket API every 30 s. A client that leaves 3 pings in a row without a pong or a message is terminated. Before this, dead connections were only cleaned up when a send stalled. No ping is sent while a connection is in backpressure mode, because a ping waits behind the backlog there; the existing send watchdog covers that case.
  • The dashboard makes one automatic reconnect attempt when a connection drops, then falls back to the "Connection lost" page. Event listeners are registered once; before, every reconnect added another set.
  • ws-client connect() now fails when the server closes the connection before it is ready. Before, the call never returned, which could leave the dashboard on "Connecting…".

Not done from the issue: showing the result of a running commissioning after a reconnect. Once the connection stays up, that case is rare.

Remote-path behaviour is not yet confirmed; the reporter will recheck after a release.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 25, 2026 12:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A drained burst can leave a connection in queued mode indefinitely, suppressing keepalive pings and allowing proxy idle timeouts to recur.

1 open issue
What changed in this PR

This PR addresses #1213 by adding WebSocket keepalives and improving dashboard recovery from dropped connections.

Changes:

  • Send periodic server pings and terminate unresponsive clients, while deferring to backpressure handling during queued sends.
  • Attempt one automatic dashboard reconnect and register event listeners only once.
  • Reject client connection attempts when the server closes before sending server information, with regression coverage.
File Description
packages/​ws-controller/​test/​WsBackpressureLatencyReproTest.ts Adapt the socket fake to the keepalive interface.
packages/​ws-controller/​test/​WebSocketConnectionTest.ts Test ping intervals, responses, termination, backpressure, and disposal.
packages/​ws-controller/​src/​server/​WebSocketConnection.ts Add keepalive timers and unanswered-ping tracking.
packages/​ws-client/​test/​WsClientTest.ts Test connection rejection on early server closure.
packages/​ws-client/​src/​connection.ts Reject pending connection setup when the socket closes.
packages/​dashboard/​src/​pages/​matter-dashboard-app.ts Add automatic reconnect and avoid duplicate listeners.
CHANGELOG.md Document keepalive and connection-recovery changes.

Review effort: Balanced

…e mode

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Keepalive behavior through the affected remote-proxy path remains unconfirmed and needs human validation.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@Apollon77
Apollon77 merged commit 4d929bb into main Oct 25, 2026
22 checks passed
@Apollon77
Apollon77 deleted the fix/ws-keepalive branch October 25, 2026 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants