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/streamseq,
../../stream/connection, ../../stream/connection,
../../multiaddress, ../../multiaddress,
../../peerinfo ../../peerinfo,
../../errors
export protocol export protocol
@ -77,8 +78,8 @@ proc handleConn*(s: Secure,
proc cleanup() {.async.} = proc cleanup() {.async.} =
try: try:
await conn.join() await conn.join() or sconn.join()
await sconn.close() 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.

View File

@ -77,12 +77,9 @@ proc connHandler*(t: TcpTransport,
trace "Cleaning up client", addrs = $client.remoteAddress, trace "Cleaning up client", addrs = $client.remoteAddress,
conn conn
if not(isNil(conn) and conn.closed()):
await conn.close()
t.clients[dir].keepItIf( it != client ) t.clients[dir].keepItIf( it != client )
if not(isNil(client) and client.closed()): await allFuturesThrowing(
await client.closeWait() conn.close(), client.closeWait())
trace "Cleaned up client", addrs = $client.remoteAddress, trace "Cleaned up client", addrs = $client.remoteAddress,
conn conn