fix leaks
This commit is contained in:
parent
fef6c43967
commit
da03656164
|
@ -33,6 +33,7 @@ method initStream*(s: ChronosStream) =
|
|||
|
||||
proc init*(C: type ChronosStream,
|
||||
client: StreamTransport,
|
||||
dir: Direction,
|
||||
timeout = DefaultChronosStreamTimeout): ChronosStream =
|
||||
result = C(client: client,
|
||||
timeout: timeout)
|
||||
|
|
|
@ -100,20 +100,8 @@ proc connHandler*(t: TcpTransport,
|
|||
if not isNil(t.handler):
|
||||
t.handlers &= t.handler(conn)
|
||||
|
||||
proc cleanup() {.async.} =
|
||||
try:
|
||||
await client.join()
|
||||
trace "cleaning up client", addrs = $client.remoteAddress, connoid = $conn.oid
|
||||
if not(isNil(conn)):
|
||||
await conn.close()
|
||||
t.clients.keepItIf(it != client)
|
||||
except CancelledError as exc:
|
||||
raise exc
|
||||
except CatchableError as exc:
|
||||
trace "error cleaning up client", exc = exc.msg
|
||||
|
||||
t.clients.add(client)
|
||||
asyncCheck cleanup()
|
||||
t.conns.incl(stream)
|
||||
asyncCheck t.cleanup(stream)
|
||||
result = conn
|
||||
|
||||
proc connCb(server: StreamServer,
|
||||
|
@ -159,7 +147,7 @@ method close*(t: TcpTransport) {.async, gcsafe.} =
|
|||
await procCall Transport(t).close() # call base
|
||||
|
||||
checkFutures(await allFinished(
|
||||
toSeq(t.conns).mapIt(it.client.closeWait())))
|
||||
toSeq(t.conns).mapIt(it.close())))
|
||||
|
||||
# server can be nil
|
||||
if not isNil(t.server):
|
||||
|
|
|
@ -10,7 +10,7 @@ const
|
|||
StreamServerTrackerName = "stream.server"
|
||||
|
||||
trackerNames = [
|
||||
# ConnectionTrackerName,
|
||||
ConnectionTrackerName,
|
||||
BufferStreamTrackerName,
|
||||
TcpTransportTrackerName,
|
||||
StreamTransportTrackerName,
|
||||
|
|
|
@ -205,14 +205,18 @@ suite "TCP transport":
|
|||
transports.add(TcpTransport.init(maxIncoming = 2))
|
||||
asyncCheck transports[0].listen(ma, connHandler)
|
||||
|
||||
var conns: seq[Connection]
|
||||
try:
|
||||
for i in 0..10:
|
||||
let transport = TcpTransport.init()
|
||||
transports.add(transport)
|
||||
discard await transport.dial(transports[0].ma).wait(10.millis)
|
||||
conns.add(await transport.dial(transports[0].ma).wait(10.millis))
|
||||
except AsyncTimeoutError:
|
||||
check times == 2
|
||||
|
||||
await allFuturesThrowing(
|
||||
conns.mapIt(it.close()))
|
||||
|
||||
await allFuturesThrowing(
|
||||
transports.mapIt(it.close()))
|
||||
|
||||
|
@ -229,14 +233,18 @@ suite "TCP transport":
|
|||
transports.add(TcpTransport.init())
|
||||
asyncCheck transports[0].listen(ma, connHandler)
|
||||
|
||||
var conns: seq[Connection]
|
||||
try:
|
||||
let transport = TcpTransport.init(maxOutgoing = 2)
|
||||
transports.add(transport)
|
||||
for i in 0..10:
|
||||
discard await transport.dial(transports[0].ma)
|
||||
conns.add(await transport.dial(transports[0].ma))
|
||||
except TooManyConnections:
|
||||
check times == 2
|
||||
|
||||
await allFuturesThrowing(
|
||||
conns.mapIt(it.close()))
|
||||
|
||||
await allFuturesThrowing(
|
||||
transports.mapIt(it.close()))
|
||||
|
||||
|
|
Loading…
Reference in New Issue