Ensure atomicity between (re)connection attempts #5273
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently reconnection is a two fold operation:
This approach produces two individual changes to
state
which can be misleading when observed from the outside. For instance:.connected
state, the first mutation increments attempt counter updating it to1
..connected
state with attempt counter updated to1
.state
to.reconnecting
with attempt counter set to1
..reconnecting
state with attempt counter set to1
.Because
connected
,reconnecting
,connecting
were handled the same way, the tunnel losing connectivity also starts connection attempt counter at1
which is suboptimal.This PR aims to fix the aforementioned issues by introducing
ReconnectReason
which is passed along withreconnect()
command in place ofshouldStopTunnelMonitor
parameter.tryStart()
then is responsible for incrementing the attempt counter following these rules:.connected
. That's because the tunnel is going to transition to.reconnecting
phase and attempt counter should start at zero during the first attempt, then increment with each subsequent attempt..connecting
or.reconnecting
as normal.Two tests added to ensure that state transitions for (re)connection attempts happen as expected.
This change is