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 <noreply@anthropic.com>
This commit is contained in:
MarekWo
2026-03-06 10:02:43 +01:00
parent 97323649c7
commit 8821892b4c
+15 -1
View File
@@ -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}")