less leak prone cleanup (#447)

* less leak prone cleanup

* fix double allFinished
This commit is contained in:
Dmitriy Ryajov 2020-11-23 18:22:15 -06:00 committed by GitHub
parent 6cc3f4283a
commit 69ae24dc8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 8 deletions

View File

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

View File

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