mirror of
https://github.com/fosrl/newt.git
synced 2026-07-16 03:46:25 -05:00
The control websocket had no read deadline and only sent application-level "newt/ping" JSON (never protocol PING frames), so a half-open connection — for example a cloud load balancer keeping the socket open after the backend API server restarted — was never detected. ReadMessage blocked forever while the buffered ping writes kept succeeding, so newt stayed "connected" to a dead peer and only recovered after a manual restart. - Arm a read deadline (pongWait = 2x pingInterval, min 20s) and refresh it on every pong and every inbound message. - Send a protocol-level PING alongside the existing app ping, so a compliant server replies with a PONG that refreshes the read deadline. - On ping-write failure, close the connection and let the read pump perform a single reconnect (previously sendPing and the read-pump defer could both trigger a reconnect, racing two connections). - Give each connection a lifecycle channel so its ping monitor stops when the connection ends (previously one ping-monitor goroutine leaked per reconnect).