From dd173738c8ba33c16a0ca4a2e2aa0298fec8525e Mon Sep 17 00:00:00 2001 From: Mattias <30832155+bammab@users.noreply.github.com> Date: Sat, 26 Oct 2024 16:16:56 +0200 Subject: [PATCH] Fix reconnect If the watchdog trigger connection_lost and the serial connection if already open, it is not possible to close/abort the connection. Old: - Watchdog timout - connection_lost (transport set to None) - _reconnect - _disconnect (which could not abort, because transport not set anymore) - _create_connection Call pyserial-asyncio: create_serial_connection -> _ensure_reader -> _read_ready -> _close -> connection_lost (end here, because of lock) New workflow could abort the transport and the new connection will work. Anyway connection_lost will be called twice: 1. by the watchdog (with TimeoutError) 2. by _reconnect -> _disconnect -> abort The last one will do nothing more, because of the lock of _reconnect --- sml/asyncio.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sml/asyncio.py b/sml/asyncio.py index c721fe6..fb96c25 100644 --- a/sml/asyncio.py +++ b/sml/asyncio.py @@ -86,7 +86,6 @@ def data_received(self, data: bytes): def connection_lost(self, exc: Optional[Exception]): logger.debug('port closed') - self._transport = None if self._running and not self._lock.locked(): asyncio.ensure_future(self._reconnect(), loop=self._loop)