Remove error_channel and simplify how we close peer connections #2796
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.
Replaces #2794 with a simpler solution.
Existing behavior -
try_break!
on certain errors will send an error event to theerror_channel
peers.check_connection
tries to read off theerror_channel
close_channel
close_channel
So we have -
In addition
try_break!
also breaks out of the connection poll loop and immediately closes the connection.So none of the above actually affects anything. We have already broken out of the poll loop and we will never read from the peer specific
close_channel
.This PR simplifies all of the above by replacing the "put an error event on the error_channel" with a simple "stop (close connection) and remove peer".
There is no need for the
error_channel
as we can close peer connection directly without this intermediate layer of indirection.There are 3 places where we actually use these connections -
For (1) we want to close the connection if
try_break!
encounters a serious enough peer related error.We already handle this by breaking out of the poll loop (error_channel never actually used).
For (2) and (3) we now simply
close()
and remove the peer from our list of peers.Previously we were relying on the complex
is_connected()
logic to identify a closed or error condition peer connection (and for it to internally clean up the peer and connection).We now simply attempt to send the msg and on error close the connection (for both ping and broadcast paths).
Related - #2801 removes option wrapper on the peer connection which will make
peer.is_connected()
here even simpler as we no longer need to handle the case where a peer has no initialized connection.