mirror of
https://github.com/meshcore-dev/meshcore_py.git
synced 2026-04-20 22:13:49 +00:00
G4: F18 — add timeout to serial_cx.connect() event wait
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
This commit is contained in:
parent
e475a567f0
commit
d6197dc71e
1 changed files with 8 additions and 4 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue