Added log handling for failed phone connection to the gateway
CI / Gateway plugin tests (push) Successful in 4m50s
CI / Kotlin tests (android host + desktop) (push) Successful in 6m45s

This commit is contained in:
ARIA committed 2026-08-22 21:08:06 +02:00
1 parent 4866f14231
commit 27dc7917f2
1 file changed
+9 -1
+9 -1
View File
@@ -483,12 +483,18 @@ class HttpServer:
# Register BEFORE the replay so a frame appended in between is
# fanned out to us (and de-duped by cursor below) instead of lost.
self._add_sub(sub)
reason = "eof"
try:
handler.send_response(200)
handler.send_header("Content-Type", "text/event-stream")
handler.send_header("Cache-Control", "no-cache")
handler.send_header("X-Accel-Buffering", "no")
handler.end_headers()
# INFO (not DEBUG like the per-request log): the stream
# lifecycle is the primary "is the device connected?" signal
# for debugging flaky links — a gap here is invisible at the
# gateway's default log level.
logger.info("android: SSE stream opened: %s (cursor=%d)", device_id, cursor)
# 1. Catch-up from the outbox (id = cursor; the envelope also
# carries the cursor for the app's push dedupe).
max_cursor = cursor
@@ -515,6 +521,7 @@ class HttpServer:
self._write_raw(handler, ": hb\n\n")
continue
if item is _STOP:
reason = "stopped"
break
c, data = item
if c is not None and c <= max_cursor:
@@ -523,8 +530,9 @@ class HttpServer:
except (BrokenPipeError, ConnectionResetError, OSError):
# Client went away mid-stream: normal (the app reconnects with
# Last-Event-ID and catches up from the outbox).
pass
reason = "client-gone"
finally:
logger.info("android: SSE stream closed: %s (%s)", device_id, reason)
self._remove_sub(sub)
@staticmethod