From 5d9239ef17087ce7cc240b2843ee75567d569f78 Mon Sep 17 00:00:00 2001 From: kdeme Date: Thu, 18 Apr 2019 14:33:38 +0200 Subject: [PATCH] Quick fix for when removePeer gets called before dispatcher is initialized --- eth/p2p/rlpx.nim | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/eth/p2p/rlpx.nim b/eth/p2p/rlpx.nim index 43e2d2e..5b572c6 100644 --- a/eth/p2p/rlpx.nim +++ b/eth/p2p/rlpx.nim @@ -1122,10 +1122,13 @@ proc removePeer(network: EthereumNode, peer: Peer) = if network.peerPool != nil and not peer.remote.isNil: network.peerPool.connectedNodes.del(peer.remote) - for observer in network.peerPool.observers.values: - if not observer.onPeerDisconnected.isNil: - if observer.protocol.isNil or peer.supports(observer.protocol): - observer.onPeerDisconnected(peer) + # Note: we need to do this check as disconnect (and thus removePeer) + # currently can get called before the dispatcher is initialized. + if not peer.dispatcher.isNil: + for observer in network.peerPool.observers.values: + if not observer.onPeerDisconnected.isNil: + if observer.protocol.isNil or peer.supports(observer.protocol): + observer.onPeerDisconnected(peer) proc callDisconnectHandlers(peer: Peer, reason: DisconnectionReason): Future[void] = var futures = newSeqOfCap[Future[void]](allProtocols.len)