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.} =
|
proc cleanup() {.async.} =
|
||||||
try:
|
try:
|
||||||
await conn.join() or sconn.join()
|
let futs = @[conn.join(), sconn.join()]
|
||||||
await allFuturesThrowing(sconn.close(), conn.close())
|
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:
|
except CancelledError:
|
||||||
# This is top-level procedure which will work as separate task, so it
|
# This is top-level procedure which will work as separate task, so it
|
||||||
# do not need to propagate CancelledError.
|
# do not need to propagate CancelledError.
|
||||||
|
|
|
@ -73,7 +73,11 @@ proc connHandler*(t: TcpTransport,
|
||||||
|
|
||||||
proc onClose() {.async.} =
|
proc onClose() {.async.} =
|
||||||
try:
|
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,
|
trace "Cleaning up client", addrs = $client.remoteAddress,
|
||||||
conn
|
conn
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue