From 4e12d0d97ad1b4fb6e04320e87f2a739a0cc557d Mon Sep 17 00:00:00 2001 From: Giovanni Petrantoni Date: Thu, 9 Jul 2020 17:20:45 +0900 Subject: [PATCH] nil check peer before disconnect --- libp2p/protocols/pubsub/floodsub.nim | 3 ++- libp2p/protocols/pubsub/gossipsub.nim | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libp2p/protocols/pubsub/floodsub.nim b/libp2p/protocols/pubsub/floodsub.nim index f629270b0..c83c2664d 100644 --- a/libp2p/protocols/pubsub/floodsub.nim +++ b/libp2p/protocols/pubsub/floodsub.nim @@ -138,7 +138,8 @@ method publish*(f: FloodSub, let (published, failed) = await f.sendHelper(f.floodsub.getOrDefault(topic), @[msg]) for p in failed: let peer = f.peers.getOrDefault(p) - f.handleDisconnect(peer) # cleanup failed peers + if not isNil(peer): + f.handleDisconnect(peer) # cleanup failed peers libp2p_pubsub_messages_published.inc(labelValues = [topic]) diff --git a/libp2p/protocols/pubsub/gossipsub.nim b/libp2p/protocols/pubsub/gossipsub.nim index 9494b1872..0fa25d25e 100644 --- a/libp2p/protocols/pubsub/gossipsub.nim +++ b/libp2p/protocols/pubsub/gossipsub.nim @@ -450,7 +450,7 @@ method rpcHandler*(g: GossipSub, let (published, failed) = await g.sendHelper(toSendPeers, m.messages) for p in failed: let peer = g.peers.getOrDefault(p) - if not(isNil(peer)): + if not isNil(peer): g.handleDisconnect(peer) # cleanup failed peers trace "forwared message to peers", peers = published.len @@ -523,7 +523,8 @@ method publish*(g: GossipSub, let (published, failed) = await g.sendHelper(peers, @[msg]) for p in failed: let peer = g.peers.getOrDefault(p) - g.handleDisconnect(peer) # cleanup failed peers + if not isNil(peer): + g.handleDisconnect(peer) # cleanup failed peers if published.len > 0: libp2p_pubsub_messages_published.inc(labelValues = [topic])