From 164892776b2b5d0681a5b410e5ff3f01561f2825 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Wed, 25 Nov 2020 07:35:25 -0600 Subject: [PATCH] get rid of hangs cleanup (#453) --- libp2p/protocols/secure/secure.nim | 9 +++++++-- libp2p/transports/tcptransport.nim | 6 +++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/libp2p/protocols/secure/secure.nim b/libp2p/protocols/secure/secure.nim index 0fe40ebe6..3809ae089 100644 --- a/libp2p/protocols/secure/secure.nim +++ b/libp2p/protocols/secure/secure.nim @@ -78,8 +78,13 @@ proc handleConn*(s: Secure, proc cleanup() {.async.} = try: - await conn.join() or sconn.join() - await allFuturesThrowing(sconn.close(), conn.close()) + let futs = @[conn.join(), sconn.join()] + await futs[0] or futs[1] + for f in futs: + if not f.finished: f.cancel # cancel outstanding 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 43f1e5c19..655246431 100644 --- a/libp2p/transports/tcptransport.nim +++ b/libp2p/transports/tcptransport.nim @@ -73,7 +73,11 @@ proc connHandler*(t: TcpTransport, proc onClose() {.async.} = try: - await client.join() or conn.join() + let futs = @[client.join(), conn.join()] + await futs[0] or futs[1] + for f in futs: + if not f.finished: f.cancel # cancel outstanding join() + trace "Cleaning up client", addrs = $client.remoteAddress, conn