mirror of https://github.com/vacp2p/nim-libp2p.git
get rid of hangs cleanup (#453)
This commit is contained in:
parent
21110636cb
commit
164892776b
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue