From 287369ac9040c430bcb0b66fbaabfcaee98bb164 Mon Sep 17 00:00:00 2001 From: viewit Date: Sat, 15 Aug 2026 11:27:50 +0200 Subject: [PATCH] fix(mqtt): wrap SUBSCRIBE packet ID instead of growing unbounded self._pid was incremented on every _subscribe() call (i.e. every connect/reconnect) but encoded as a 16-bit field via pid.to_bytes(2, "big"), which only accepts 1-65535. A long-lived bridge with frequent MQTT reconnects eventually overflowed the counter, raising "OverflowError: int too big to convert" on every subsequent connect attempt - including the manual "Connect" button, which silently 500'd while the background poll loop kept reconnecting regardless, making the bug easy to miss. Wrap back to 1 at the 16-bit boundary instead of growing forever. --- kobrax_client.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kobrax_client.py b/kobrax_client.py index a234e73..eccfbbc 100644 --- a/kobrax_client.py +++ b/kobrax_client.py @@ -371,7 +371,12 @@ class KobraXClient: def _subscribe(self, topic: str): with self._lock: pid = self._pid - self._pid += 1 + # MQTT packet IDs are a 16-bit field (1-65535, 0 reserved) - wrap + # instead of growing unbounded, otherwise a long-lived bridge with + # frequent reconnects eventually overflows pid.to_bytes(2, "big") + # (OverflowError: int too big to convert), breaking every future + # connect attempt including the manual "Connect" button. + self._pid = 1 if self._pid >= 0xFFFF else self._pid + 1 if self._sock is not None: self._sock.sendall(_build_subscribe(topic, pid)) log.info("SUB %s", topic)