From 7cb6c81159770aeb708bf3473d4f3190d186d24c Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Mon, 15 Jun 2020 12:30:09 -0600 Subject: [PATCH] Don't modify iterables while iterating them (#219) * don't modify iterables while iterating * assert handlers to properly close connections --- libp2p/muxers/mplex/mplex.nim | 1 + libp2p/protocols/pubsub/gossipsub.nim | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libp2p/muxers/mplex/mplex.nim b/libp2p/muxers/mplex/mplex.nim index ab8889d..bf62fd0 100644 --- a/libp2p/muxers/mplex/mplex.nim +++ b/libp2p/muxers/mplex/mplex.nim @@ -118,6 +118,7 @@ method handle*(m: Mplex) {.async, gcsafe.} = # doAssert(stream.closed, "connection not closed by handler!") except CatchableError as exc: trace "exception in stream handler", exc = exc.msg + doAssert(stream.closed, "stream not closed by protocol handler") finally: m.conns.keepItIf(it != stream) m.handlerFuts.keepItIf(it != fut) diff --git a/libp2p/protocols/pubsub/gossipsub.nim b/libp2p/protocols/pubsub/gossipsub.nim index a6ed0df..e68d50d 100644 --- a/libp2p/protocols/pubsub/gossipsub.nim +++ b/libp2p/protocols/pubsub/gossipsub.nim @@ -215,7 +215,7 @@ proc heartbeat(g: GossipSub) {.async.} = await g.heartbeatLock.acquire() trace "running heartbeat" - for t in g.topics.keys: + for t in toSeq(g.topics.keys): await g.rebalanceMesh(t) await g.dropFanoutPeers()