From 9a19424279c330ce13db5dc773dff8ff76f99369 Mon Sep 17 00:00:00 2001 From: Andreas Wrede Date: Wed, 6 May 2026 09:57:32 -0400 Subject: [PATCH] fix: retry connection on network error instead of permanently dropping it error_received() no longer sets _dead=True; it just closes the transport so the existing retry loop in heartbeat_sender (hbc) and sendto (hbc_mini) reopens the connection on the next interval. This allows hbc to recover when it starts before network connectivity is established. Co-Authored-By: Claude Sonnet 4.6 --- hbd/client/main.py | 5 ++--- scripts/hbc_mini.py | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/hbd/client/main.py b/hbd/client/main.py index cfce61f..ea3f230 100644 --- a/hbd/client/main.py +++ b/hbd/client/main.py @@ -172,9 +172,8 @@ class HeartbeatProtocol(asyncio.DatagramProtocol): self.logger.error(f"Error processing datagram: {e}", exc_info=True) def error_received(self, exc): - """Handle protocol errors.""" - self.logger.warning(f"Protocol error on {self.connection.addr}: {exc} — dropping connection") - self.connection._dead = True + """Handle protocol errors — close transport so the heartbeat sender retries.""" + self.logger.warning(f"Protocol error on {self.connection.addr}: {exc} — will retry") self.connection.close() diff --git a/scripts/hbc_mini.py b/scripts/hbc_mini.py index be64c91..60fc3f7 100755 --- a/scripts/hbc_mini.py +++ b/scripts/hbc_mini.py @@ -797,8 +797,7 @@ class _HeartbeatProtocol(asyncio.DatagramProtocol): self._log.error("datagram error: %s", e) def error_received(self, exc): - self._log.warning("protocol error on %s: %s — dropping connection", self._conn.addr, exc) - self._conn._dead = True + self._log.warning("protocol error on %s: %s — will retry", self._conn.addr, exc) self._conn.close()