Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for handshake to finish to allow for clean disconnect when stopping reconnect logic #614

Merged
merged 3 commits into from
Nov 6, 2023

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Nov 6, 2023

There was a very rare race where we could disconnect in the middle of the handshake if we had just finished connecting to the ESP which would prevent the disconnect request from being seen by the ESP

To fix this we now only cancel without the lock if we are still establishing the connection, otherwise try to wait for the handshake to finish so we can cleanly disconnect.

This didn't cause any visible issues besides a log message on the esp

…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
…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
…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
Copy link

codecov bot commented Nov 6, 2023

Codecov Report

Merging #614 (6eb9ff1) into main (2ef9ed9) will increase coverage by 0.41%.
Report is 1 commits behind head on main.
The diff coverage is 50.00%.

❗ Current head 6eb9ff1 differs from pull request most recent head 9ade838. Consider uploading reports for the commit 9ade838 to get more accurate results

@@            Coverage Diff             @@
##             main     #614      +/-   ##
==========================================
+ Coverage   77.41%   77.83%   +0.41%     
==========================================
  Files          14       14              
  Lines        2488     2490       +2     
==========================================
+ Hits         1926     1938      +12     
+ Misses        562      552      -10     
Files Coverage Δ
aioesphomeapi/reconnect_logic.py 87.83% <50.00%> (+1.19%) ⬆️

... and 1 file with indirect coverage changes

📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today!

@bdraco bdraco changed the title Speed up stopping the reconnect logic if we are at a safe place to cancel Wait for handshake to finish to allow for clean disconnect when stopping reconnect logic Nov 6, 2023
@bdraco bdraco merged commit 0683521 into main Nov 6, 2023
@bdraco bdraco deleted the stop_trying_to_connect_on_stop branch November 6, 2023 22:46
bdraco added a commit that referenced this pull request Nov 7, 2023
#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant