From eb13845f6537a0af7564d3d4b535d88938eb104a Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Wed, 19 Aug 2020 12:28:18 +0200 Subject: [PATCH] work around send that may raise `send` can raise exceptions that together with asyncCheck will crash NBC --- libp2p/protocols/pubsub/pubsub.nim | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/libp2p/protocols/pubsub/pubsub.nim b/libp2p/protocols/pubsub/pubsub.nim index 534dbfa07..6bad2d85b 100644 --- a/libp2p/protocols/pubsub/pubsub.nim +++ b/libp2p/protocols/pubsub/pubsub.nim @@ -8,7 +8,7 @@ ## those terms. import std/[tables, sequtils, sets] -import chronos, chronicles, metrics +import chronos, chronicles, chronicles/chronos_tools, metrics import pubsubpeer, rpc/[message, messages], ../../switch, @@ -107,9 +107,9 @@ proc broadcast*( proc sendSubs*(p: PubSub, peer: PubSubPeer, topics: seq[string], - subscribe: bool) {.async.} = + subscribe: bool): Future[void] = ## send subscriptions to remote peer - await p.send( + p.send( peer, RPCMsg( subscriptions: topics.mapIt(SubOpts(subscribe: subscribe, topic: it))), @@ -197,7 +197,11 @@ method subscribePeer*(p: PubSub, peer: PeerID) {.base.} = let pubsubPeer = p.getOrCreatePeer(peer, p.codec) if p.topics.len > 0: - asyncCheck p.sendSubs(pubsubPeer, toSeq(p.topics.keys), true) + # TODO sendSubs may raise, but doing asyncCheck here causes the exception + # to escape to the poll loop. + # With a bit of luck, it may be harmless to ignore exceptions here - + # some cleanup is eventually done in PubSubPeer.send + traceAsyncErrors p.sendSubs(pubsubPeer, toSeq(p.topics.keys), true) pubsubPeer.subscribed = true