From 5235e01b8dac36a847723fc83cfd5ff65c903215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Wed, 27 May 2015 18:58:51 +0300 Subject: [PATCH] eth: hard disconnect if a peer is flaky --- eth/handler.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/eth/handler.go b/eth/handler.go index 777a9c7c0e..8092a5f714 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -93,14 +93,22 @@ func NewProtocolManager(protocolVersion, networkId int, mux *event.TypeMux, txpo } func (pm *ProtocolManager) removePeer(id string) { - // Unregister the peer from the downloader - pm.downloader.UnregisterPeer(id) + // Short circuit if the peer was already removed + peer := pm.peers.Peer(id) + if peer == nil { + return + } + glog.V(logger.Debug).Infoln("Removing peer", id) - // Remove the peer from the Ethereum peer set too - glog.V(logger.Detail).Infoln("Removing peer", id) + // Unregister the peer from the downloader and Ethereum peer set + pm.downloader.UnregisterPeer(id) if err := pm.peers.Unregister(id); err != nil { glog.V(logger.Error).Infoln("Removal failed:", err) } + // Hard disconnect at the networking layer + if peer != nil { + peer.Peer.Disconnect(p2p.DiscUselessPeer) + } } func (pm *ProtocolManager) Start() {