From f62ca5607d249237fe3df97c14b471e5798b023e Mon Sep 17 00:00:00 2001 From: deme Date: Mon, 12 Nov 2018 13:54:15 +0100 Subject: [PATCH] Fix segfault when there is no peer_pool (no connectToNetwork() ran). e.g. tserver test would segfault. --- eth_p2p.nim | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/eth_p2p.nim b/eth_p2p.nim index 07caf12..d5dfab6 100644 --- a/eth_p2p.nim +++ b/eth_p2p.nim @@ -58,14 +58,15 @@ proc processIncoming(server: StreamServer, yield peerfut if not peerfut.failed: let peer = peerfut.read() - if peer.remote notin node.peerPool.connectedNodes: - node.peerPool.connectedNodes[peer.remote] = peer - for o in node.peerPool.observers.values: - if not o.onPeerConnected.isNil: - o.onPeerConnected(peer) - else: - debug "Disconnecting already connected node" - await peer.disconnect(AlreadyConnected) + if node.peerPool != nil: + if peer.remote notin node.peerPool.connectedNodes: + node.peerPool.connectedNodes[peer.remote] = peer + for o in node.peerPool.observers.values: + if not o.onPeerConnected.isNil: + o.onPeerConnected(peer) + else: + debug "Disconnecting already connected node" + await peer.disconnect(AlreadyConnected) else: remote.close()