Skip to content

Commit

Permalink
Speed up stopping the reconnect logic if we are at a safe place to ca…
Browse files Browse the repository at this point in the history
…ncel

If the connection has not established yet, we can cancel the
connection process when the reconnect logic is stopped instead
of waiting for the connection to fail. If we have already
finished connecting and started the handshake, we wait
for it to complete so we can try to disconnect cleanly
  • Loading branch information
bdraco committed Nov 6, 2023
1 parent f4d297a commit 6eb9ff1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion aioesphomeapi/reconnect_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,10 @@ async def start(self) -> None:
async def stop(self) -> None:
"""Stop the connecting logic background task. Does not disconnect the client."""
self._cancel_connect("Stopping")
if self._connect_task and self._connection_state == ReconnectLogicState.CONNECTING:
if (
self._connect_task
and self._connection_state == ReconnectLogicState.CONNECTING
):
# 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 6eb9ff1

Please sign in to comment.