From 97abe77398261b71ea883332144234d1fdfea249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C8=98tefan=20Talpalaru?= Date: Sun, 29 Mar 2020 23:56:25 +0200 Subject: [PATCH] close unused PeerInfo instance Should not be needed from the GC's point of view, but needed when gathering Future.state statistics, due to `PeerInfo.lifefut`. --- beacon_chain/eth2_network.nim | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/beacon_chain/eth2_network.nim b/beacon_chain/eth2_network.nim index d5cdd48a0..65f50c0d4 100644 --- a/beacon_chain/eth2_network.nim +++ b/beacon_chain/eth2_network.nim @@ -663,13 +663,16 @@ proc runDiscoveryLoop*(node: Eth2Node) {.async.} = try: let discoveredPeers = node.discovery.randomNodes(node.wantedPeers - currentPeerCount) - debug "Discovered peers", peer = $discoveredPeers for peer in discoveredPeers: try: let peerInfo = peer.record.toTypedRecord.toPeerInfo - if peerInfo != nil and peerInfo.id notin node.switch.connections: - # TODO do this in parallel - await node.dialPeer(peerInfo) + if peerInfo != nil: + if peerInfo.id notin node.switch.connections: + debug "Discovered new peer", peer = $peer + # TODO do this in parallel + await node.dialPeer(peerInfo) + else: + peerInfo.close() except CatchableError as err: debug "Failed to connect to peer", peer = $peer, err = err.msg except CatchableError as err: