get rid of hangs cleanup (#453)

This commit is contained in:
Dmitriy Ryajov 2020-11-25 07:35:25 -06:00 committed by GitHub
parent 21110636cb
commit 164892776b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View File

@ -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.

View File

@ -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