From dc8c7ad1d6745334ac475946829911999bb4423e Mon Sep 17 00:00:00 2001 From: MarekWo Date: Fri, 6 Mar 2026 10:05:17 +0100 Subject: [PATCH] fix(channels): pre-allocate reader.channels to prevent lib corruption meshcore lib 2.2.21 bug: reader.py line 434 does self.channels = self.channels.extend([...]) which sets self.channels = None (extend returns None). This corrupts ALL subsequent channel message processing. Fix: after getting max_channels from device_info, pre-allocate mc._reader.channels to max_channels slots so the extend path is never triggered. Co-Authored-By: Claude Opus 4.6 --- app/device_manager.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/device_manager.py b/app/device_manager.py index d9d8c7b..8c1b1e8 100644 --- a/app/device_manager.py +++ b/app/device_manager.py @@ -178,6 +178,16 @@ class DeviceManager: except Exception as e: logger.warning(f"Could not fetch device_info: {e}") + # Workaround: meshcore lib 2.2.21 has a bug where list.extend() + # return value (None) corrupts reader.channels for idx >= 20. + # Pre-allocate the channels list to max_channels to avoid this. + reader = getattr(self.mc, '_reader', None) + if reader and hasattr(reader, 'channels'): + current = reader.channels or [] + if len(current) < self._max_channels: + reader.channels = current + [{} for _ in range(self._max_channels - len(current))] + logger.debug(f"Pre-allocated reader.channels to {len(reader.channels)} slots") + logger.info(f"Connected to device: {self._device_name} " f"(key: {self._self_info.get('public_key', '?')[:8]}...)")