From d6197dc71ea70decb352423038f291b69f0ae8c6 Mon Sep 17 00:00:00 2001 From: Matthew Wolter Date: Sat, 11 Apr 2026 20:23:44 -0700 Subject: [PATCH] =?UTF-8?q?G4:=20F18=20=E2=80=94=20add=20timeout=20to=20se?= =?UTF-8?q?rial=5Fcx.connect()=20event=20wait?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Why: After create_serial_connection, connect() awaited _connected_event.wait() with no timeout. If the serial device opened but connection_made was never called (driver bug, USB adapter glitch), connect() hung indefinitely. Now wrapped in asyncio.wait_for with a configurable timeout (default 10s). asyncio.TimeoutError propagates to the caller for clean failure handling. Refs: Forensics report finding F18 --- src/meshcore/serial_cx.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/meshcore/serial_cx.py b/src/meshcore/serial_cx.py index 24aaef7..fa7b1a2 100644 --- a/src/meshcore/serial_cx.py +++ b/src/meshcore/serial_cx.py @@ -52,12 +52,16 @@ class SerialConnection: def resume_writing(self): logger.debug("resume writing") - async def connect(self): + async def connect(self, timeout: float = 10.0): """ - Connects to the device + Connects to the device. + + Args: + timeout: Maximum seconds to wait for connection_made callback. + Defaults to 10.0. Raises asyncio.TimeoutError on expiry. """ self._connected_event.clear() - + loop = asyncio.get_running_loop() await serial_asyncio.create_serial_connection( loop, @@ -66,7 +70,7 @@ class SerialConnection: baudrate=self.baudrate, ) - await self._connected_event.wait() + await asyncio.wait_for(self._connected_event.wait(), timeout=timeout) logger.info("Serial Connection started") return self.port