fix: robust router send with auto-reconnect, 10ms timeout
Validate and Test / validate-patches (push) Failing after 13s

- try_send() helper: reconnect on send failure
- 10ms socket timeout instead of 300ms (stalls poll loop)
- Refresh path also uses try_send
- Remove committed library bloat from repo (add .gitignore)
This commit is contained in:
2026-06-24 04:46:59 -07:00
parent f70a8701c9
commit 3b40592055
47 changed files with 22 additions and 47591 deletions
+18 -8
View File
@@ -47,7 +47,7 @@ def render(active_notes):
def connect_router():
router = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
router.setblocking(False)
router.settimeout(0.01)
try:
router.connect(ROUTER_SOCK)
except OSError:
@@ -55,6 +55,18 @@ def connect_router():
return router
def try_send(router, data):
try:
router.sendall(data)
return router, True
except (BlockingIOError, OSError):
try:
router.close()
except OSError:
pass
return connect_router(), False
def main():
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
@@ -131,11 +143,11 @@ def main():
# Try to send pending frame — no POLLOUT dependency
if pending_bytes is not None:
try:
router.sendall(pending_bytes)
router, ok = try_send(router, pending_bytes)
if ok:
pending_bytes = None
frames_sent += 1
except (BlockingIOError, OSError):
else:
frames_dropped += 1
# Background refresh: resend last params to recover from router drops
@@ -145,11 +157,9 @@ def main():
if last_sent_params is not None and pending_bytes is None:
msg_id = (msg_id + 1) % 65535
refresh_bytes = packer.pack([0, msg_id, "draw_frame", last_sent_params])
try:
router.sendall(refresh_bytes)
router, ok = try_send(router, refresh_bytes)
if ok:
frames_sent += 1
except (BlockingIOError, OSError):
pass
if now - stats_last_write >= 2.0:
fps = fps_sample_frames / (now - fps_sample_start) if (now - fps_sample_start) > 0 else 0