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.
This commit is contained in:
@ -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)
|
||||
|
||||
Reference in New Issue
Block a user