From aded78f2597293d8c75595fb334cf307d3328812 Mon Sep 17 00:00:00 2001 From: Giovanni Petrantoni Date: Tue, 21 Jul 2020 13:37:06 +0900 Subject: [PATCH] don't delete while iterating in score update --- libp2p/protocols/pubsub/gossipsub.nim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libp2p/protocols/pubsub/gossipsub.nim b/libp2p/protocols/pubsub/gossipsub.nim index fed05e66b..2d7b84cc9 100644 --- a/libp2p/protocols/pubsub/gossipsub.nim +++ b/libp2p/protocols/pubsub/gossipsub.nim @@ -468,13 +468,14 @@ proc updateScores(g: GossipSub) = # avoid async debug "updating scores", peers = g.peers.len let now = Moment.now() + var evicting: seq[PubSubPeer] for peer, stats in g.peerStats.mpairs: debug "updating peer score", peer, gossipTopics = peer.topics.len if not peer.connected: if now > stats.expire: - g.peerStats.del(peer) + evicting.add(peer) debug "evicted peer from memory", peer continue @@ -540,6 +541,9 @@ proc updateScores(g: GossipSub) = # avoid async stats.topicInfos[topic] = info debug "updated peer's score", peer, score = peer.score + + for peer in evicting: + g.peerStats.del(peer) proc heartbeat(g: GossipSub) {.async.} = while g.heartbeatRunning: