fix logic issue: handlers.removePeer() is called twice. #856
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.
Description
There is a logic issue which causes "Ethereum peer removal failed, err=peer not registered" occur quite often.
Related issues #220 #670 #821
Rationale
handler.runEthPeer()
set up adefer removePeer().
This is always called after a peer is disconnected.However removePeer is also called by multiple functions like downloader/fetcher. After those kind of functions call
removePeer()
, peer handler executesdefer removePeer()
. This makesremovePeer()
happened twice, and this is the reason we often see "Ethereum peer removal failed, err=peer not registered".Just took a look, go-ethereum code here is exactly using this new logic
Changes
Notable changes:
removePeer()
hard Disconnect peer from networking layer.defer unregisterPeer()
will called byhandler.runEthPeer()
, do the cleanup task after then.NewPeerPipe()
underp2p.Peer
, for RW close testing. The code is referenced from go-ethereum-p2p-peer