diff --git a/libp2p/switch.nim b/libp2p/switch.nim index cf32bcc8e..2f284ab1a 100644 --- a/libp2p/switch.nim +++ b/libp2p/switch.nim @@ -335,16 +335,16 @@ proc stop*(s: Switch) {.async.} = # we want to report erros but we do not want to fail # or crash here, cos we need to clean possibly MANY items # and any following conn/transport won't be cleaned up - var futs = newSeq[Future[void]]() - if s.pubSub.isSome: - futs &= s.pubSub.get().stop() + await s.pubSub.get().stop() - futs &= toSeq(s.connections.values).mapIt(s.cleanupConn(it)) - futs &= s.transports.mapIt(it.close()) + checkFutures( + await allFinished( + toSeq(s.connections.values).mapIt(s.cleanupConn(it)))) - futs = await allFinished(futs) - checkFutures(futs) + checkFutures( + await allFinished( + s.transports.mapIt(it.close()))) trace "switch stopped" diff --git a/libp2p/transports/tcptransport.nim b/libp2p/transports/tcptransport.nim index c9c886616..fd2d7c538 100644 --- a/libp2p/transports/tcptransport.nim +++ b/libp2p/transports/tcptransport.nim @@ -71,8 +71,9 @@ proc connHandler*(t: TcpTransport, if not isNil(t.handler): t.handlers &= t.handler(conn) - t.connections.add(conn) - t.cleanups &= t.cleanup(conn) + # TODO: store the streamtransport client here + t.connections.add(conn) + t.cleanups &= t.cleanup(conn) result = conn