diff --git a/libp2p/protocols/secure/secure.nim b/libp2p/protocols/secure/secure.nim index 61ef8c9fc..c85e560c0 100644 --- a/libp2p/protocols/secure/secure.nim +++ b/libp2p/protocols/secure/secure.nim @@ -13,7 +13,8 @@ import ../protocol, ../../stream/streamseq, ../../stream/connection, ../../multiaddress, - ../../peerinfo + ../../peerinfo, + ../../errors export protocol @@ -77,8 +78,8 @@ proc handleConn*(s: Secure, proc cleanup() {.async.} = try: - await conn.join() - await sconn.close() + await conn.join() or sconn.join() + await allFuturesThrowing(sconn.close(), conn.close()) except CancelledError: # This is top-level procedure which will work as separate task, so it # do not need to propagate CancelledError. diff --git a/libp2p/transports/tcptransport.nim b/libp2p/transports/tcptransport.nim index 07f22eb2c..43f1e5c19 100644 --- a/libp2p/transports/tcptransport.nim +++ b/libp2p/transports/tcptransport.nim @@ -77,12 +77,9 @@ proc connHandler*(t: TcpTransport, trace "Cleaning up client", addrs = $client.remoteAddress, conn - if not(isNil(conn) and conn.closed()): - await conn.close() - t.clients[dir].keepItIf( it != client ) - if not(isNil(client) and client.closed()): - await client.closeWait() + await allFuturesThrowing( + conn.close(), client.closeWait()) trace "Cleaned up client", addrs = $client.remoteAddress, conn