mirror of https://github.com/vacp2p/nim-libp2p.git
less leak prone cleanup (#447)
* less leak prone cleanup * fix double allFinished
This commit is contained in:
parent
6cc3f4283a
commit
69ae24dc8d
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue