Skip to content

[Feature] Server-side WebSocket heartbeat + idle timeout — half-open connections leak actors and maxConnections slots #651

Description

@pathosDev

Problem

The WebSocket client has a heartbeat: pingIntervalMs (src/http/websocket/WebsocketClientOptions.ts:46, driven at src/http/websocket/WebsocketClientActor.ts:178-180). The server side has no equivalent: ResolvedWebsocketPolicy covers only frame size, invalid messages, backpressure and maxConnections (src/http/websocket/WebsocketPolicy.ts:19-31), and WebsocketRouteOptionsBuilder has no withHeartbeat* / withIdleTimeout* (src/http/websocket/WebsocketRouteOptions.ts:59-105).

A peer that vanishes without a close frame keeps its WebsocketConnectionActor child and its entry in WebsocketServerActor._clients (src/http/websocket/WebsocketServerActor.ts:45) forever — and the dead connection counts against the maxConnections cap.

Proposed behaviour

Add withHeartbeatIntervalMs / withIdleTimeoutMs to WebsocketRouteOptions + HOCON under actor-ts.http.websocket, resolved by resolveWebsocketPolicy. Send protocol-level pings from the connection actor; close 1001 after N missed pongs or after idle.

Acceptance criteria

  • A socket whose peer is force-killed is reaped within the configured window on all three backends; maxConnections accounting recovers.

Related: #570 (close-before-attach leak on Hono — different mechanism, same symptom family)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpriority: highTop priority — high impact, plan next

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions