Skip to content

Fix log stream dying silently across WiFi mode switches - #107

Merged
eliasbakken merged 1 commit into
mainfrom
fix/log-stream-wifi-switch-95
Aug 11, 2026
Merged

Fix log stream dying silently across WiFi mode switches#107
eliasbakken merged 1 commit into
mainfrom
fix/log-stream-wifi-switch-95

Conversation

@eliasbakken

Copy link
Copy Markdown
Contributor

Summary

  • `streamLog()` never checked for client disconnection - the handler (and its tail follower) ran forever even after the client was gone, leaking one goroutine per dropped connection
  • Reproduced Log stream stops working after connecting to an external AP #95 directly: when the board's WiFi interface disappears mid-stream (AP/station switch), the connection goes completely silent on both ends - no RST, no read error. Neither side's error handling fires, so the client waits forever
  • `streamLog()` now watches the request context and returns/cleans up on disconnect, and sends a 15s heartbeat event
  • The client watches for the heartbeat with a 30s watchdog and reconnects itself if none arrives, instead of relying on `onerror` which never fires in this scenario

Closes #95

Test plan

  • Live-tested on real hardware: opened a raw stream connection, switched the board through an AP/station round-trip, confirmed via `ss` that the server-side connection cleaned up with no lingering CLOSE_WAIT sockets and no leaked goroutines
  • Confirmed the heartbeat event is actually emitted every 15s
  • Confirmed a fresh connection works cleanly immediately after the round-trip
  • User confirmed the log viewer keeps working across a live WiFi mode switch in the browser
  • go test ./... and bats test/bats pass

🤖 Generated with Claude Code

Two real bugs found live-testing on the board:
- streamLog() never checked for client disconnection, so the handler
  (and its tail follower) ran forever even after the client was long
  gone - one leaked goroutine per dropped EventSource connection.
- Confirmed by reproducing #95 directly: when the board's WiFi
  interface disappears mid-stream (switching AP/station mode), the
  connection goes completely silent on both ends - no RST, no read
  error, nothing. Neither side's error handling ever fires, so the
  client just waits forever with a "dead" connection that never
  reports itself as dead.

Fixes: streamLog() now watches the request context and returns (and
stops its tail follower) once the client disconnects. It also sends a
15s heartbeat event, and the client watches for it with a 30s
watchdog - if nothing arrives in time, it assumes the connection is
dead and reconnects itself rather than waiting on an onerror that may
never come.

Closes #95
@eliasbakken
eliasbakken merged commit fbf1ce1 into main Aug 11, 2026
1 check passed
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.

Log stream stops working after connecting to an external AP

1 participant