✨ feat: stream_measurements sends __ping__ every 60 s (keep-alive) #164

Merged
mat merged 1 commit from feat/ws-ping into main 2026-10-27 10:34:24 +00:00
Owner

Summary

 _consume_stream
+  every 60 s: ws.send("__ping__")            # raw text, outside STOMP — the
+                                             # server declines STOMP heart-beats
+                                             # (CONNECTED heart-beat:0,0)
+  except WebSocketTimeoutException: continue # was: unhandled → raw exception

The server declines STOMP-level heart-beating, so the SPA keeps the stream alive by sending the literal text __ping__ on the WebSocket every 60 s (no-op for the server — docs/energy.comwatt.com/websocket-realtime.md). The client now mirrors that: a time-based check in the consume loop, independent of traffic. This also fixes a latent crash: ws.recv() on a socket silent for longer than the client timeout raised WebSocketTimeoutException straight out of the generator; timeouts now just wake the ping check. A __ping__ that hits a dead socket ends the stream cleanly instead of leaking the raw websocket-client exception.

Evidence

  • Before: a site silent >30 s (client timeout) killed the generator with an unhandled WebSocketTimeoutException; no keep-alive was ever sent.
  • After: 4 new tests — __ping__ sent after 60 s of silence (exactly once), no ping before 60 s, ping still sent while frames flow (time-based), dead-socket-during-ping ends the stream with DISCONNECT teardown attempted; pytest = 211 passed; mypy clean.

Merge Danger

Door: two-way — consume-loop only; revert restores the old silence-kills-stream behavior.

Blast Radius: low — streams now send one 7-byte text frame per minute; silent streams that used to die now survive. Handshake and frame parsing unchanged.

Closes half of #101 (the /app/streaming/stop teardown follows as a stacked PR)

## Summary ```diff _consume_stream + every 60 s: ws.send("__ping__") # raw text, outside STOMP — the + # server declines STOMP heart-beats + # (CONNECTED heart-beat:0,0) + except WebSocketTimeoutException: continue # was: unhandled → raw exception ``` The server declines STOMP-level heart-beating, so the SPA keeps the stream alive by sending the literal text `__ping__` on the WebSocket every 60 s (no-op for the server — `docs/energy.comwatt.com/websocket-realtime.md`). The client now mirrors that: a time-based check in the consume loop, independent of traffic. This also fixes a latent crash: `ws.recv()` on a socket silent for longer than the client timeout raised `WebSocketTimeoutException` straight out of the generator; timeouts now just wake the ping check. A `__ping__` that hits a dead socket ends the stream cleanly instead of leaking the raw websocket-client exception. ## Evidence - **Before:** a site silent >30 s (client timeout) killed the generator with an unhandled `WebSocketTimeoutException`; no keep-alive was ever sent. - **After:** 4 new tests — `__ping__` sent after 60 s of silence (exactly once), no ping before 60 s, ping still sent while frames flow (time-based), dead-socket-during-ping ends the stream with DISCONNECT teardown attempted; `pytest` = **211 passed**; `mypy` clean. ## Merge Danger **Door:** two-way — consume-loop only; revert restores the old silence-kills-stream behavior. **Blast Radius:** low — streams now send one 7-byte text frame per minute; silent streams that used to die now survive. Handshake and frame parsing unchanged. Closes half of #101 (the `/app/streaming/stop` teardown follows as a stacked PR)
✨ feat: stream_measurements sends __ping__ every 60 s (keep-alive) (#101)
All checks were successful
Tests / forgejo-pytest (pull_request) Successful in 44s
Tests / forgejo-pytest (push) Successful in 44s
1a401c42fa
mat changed title from WIP: ✨ feat: stream_measurements sends __ping__ every 60 s (keep-alive) to ✨ feat: stream_measurements sends __ping__ every 60 s (keep-alive) 2026-10-27 10:34:21 +00:00
mat merged commit 89b789f9f9 into main 2026-10-27 10:34:24 +00:00
mat deleted branch feat/ws-ping 2026-10-27 10:34:24 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
mat/python-comwatt-client!164
No description provided.