Skip to content

Commit

Permalink
Fix reconnect
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bammab committed Oct 26, 2024
1 parent 21d6acd commit dd17373
Showing 1 changed file with 0 additions and 1 deletion.
1 change: 0 additions & 1 deletion sml/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit dd17373

Please sign in to comment.