From 8821892b4c14cbf1e8267e4b40a03d9c16d27434 Mon Sep 17 00:00:00 2001 From: MarekWo Date: Fri, 6 Mar 2026 10:02:43 +0100 Subject: [PATCH] fix(channels): stop channel iteration on consecutive empty slots meshcore lib 2.2.21 has a bug where list.extend() return value (None) is assigned to self.channels, corrupting state for indices >= 20. Stop iterating after 3 consecutive empty/failed channels to avoid hitting this bug and reduce error log spam. Co-Authored-By: Claude Opus 4.6 --- app/device_manager.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/device_manager.py b/app/device_manager.py index a9330c1..d9d8c7b 100644 --- a/app/device_manager.py +++ b/app/device_manager.py @@ -206,9 +206,16 @@ class DeviceManager: async def _load_channel_secrets(self): """Load channel secrets from device for pkt_payload computation.""" + consecutive_empty = 0 try: for idx in range(self._max_channels): - event = await self.mc.commands.get_channel(idx) + try: + event = await self.mc.commands.get_channel(idx) + except Exception: + consecutive_empty += 1 + if consecutive_empty >= 3: + break # likely past last configured channel + continue if event: data = getattr(event, 'payload', None) or {} secret = data.get('channel_secret', data.get('secret', b'')) @@ -216,6 +223,13 @@ class DeviceManager: secret = secret.hex() if secret and len(secret) == 32: self._channel_secrets[idx] = secret + consecutive_empty = 0 + else: + consecutive_empty += 1 + else: + consecutive_empty += 1 + if consecutive_empty >= 3: + break # stop after 3 consecutive empty channels logger.info(f"Cached {len(self._channel_secrets)} channel secrets") except Exception as e: logger.error(f"Failed to load channel secrets: {e}")