Skip to content

Commit

Permalink
Allow the stop callback to be cancelled when already disconnected
Browse files Browse the repository at this point in the history
#614 fixed the case were we would cancel the handshake in progress, but
it did not account for the race where we have not switched the state
to connecting yet because we have not obtained the lock. While I could
only get this to happen in a test its likely it possible in the
real world if the timing is exactly perfect
  • Loading branch information
bdraco committed Nov 7, 2023
1 parent a0239b7 commit 0fe2287
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion aioesphomeapi/reconnect_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ async def start(self) -> None:

async def stop(self) -> None:
"""Stop the connecting logic background task. Does not disconnect the client."""
if self._connection_state == ReconnectLogicState.CONNECTING:
if self._connection_state in NOT_YET_CONNECTED_STATES:
# If we are still establishing a connection, we can safely
# cancel the connect task here, otherwise we need to wait
# for the connect task to finish so we can gracefully
Expand Down

0 comments on commit 0fe2287

Please sign in to comment.