diff --git a/libp2p/muxers/mplex/lpchannel.nim b/libp2p/muxers/mplex/lpchannel.nim index 91c54fb..0cfd14e 100644 --- a/libp2p/muxers/mplex/lpchannel.nim +++ b/libp2p/muxers/mplex/lpchannel.nim @@ -139,7 +139,7 @@ method close*(s: LPChannel) {.async, gcsafe.} = method initStream*(s: LPChannel) = if s.objName.len == 0: - s.objName = "LPChannel" + s.objName = LPChannelTrackerName s.timeoutHandler = proc(): Future[void] {.gcsafe.} = trace "Idle timeout expired, resetting LPChannel", s diff --git a/libp2p/protocols/secure/secure.nim b/libp2p/protocols/secure/secure.nim index 6c66cbd..903752c 100644 --- a/libp2p/protocols/secure/secure.nim +++ b/libp2p/protocols/secure/secure.nim @@ -59,7 +59,7 @@ proc init*(T: type SecureConn, method initStream*(s: SecureConn) = if s.objName.len == 0: - s.objName = "SecureConn" + s.objName = SecureConnTrackerName procCall Connection(s).initStream() diff --git a/libp2p/stream/bufferstream.nim b/libp2p/stream/bufferstream.nim index bbcab33..8065a9d 100644 --- a/libp2p/stream/bufferstream.nim +++ b/libp2p/stream/bufferstream.nim @@ -50,7 +50,7 @@ proc len*(s: BufferStream): int = method initStream*(s: BufferStream) = if s.objName.len == 0: - s.objName = "BufferStream" + s.objName = BufferStreamTrackerName procCall Connection(s).initStream() diff --git a/libp2p/stream/connection.nim b/libp2p/stream/connection.nim index f06d962..6db6684 100644 --- a/libp2p/stream/connection.nim +++ b/libp2p/stream/connection.nim @@ -68,7 +68,7 @@ chronicles.formatIt(Connection): shortLog(it) method initStream*(s: Connection) = if s.objName.len == 0: - s.objName = "Connection" + s.objName = ConnectionTrackerName procCall LPStream(s).initStream() diff --git a/libp2p/stream/lpstream.nim b/libp2p/stream/lpstream.nim index 4d74070..9e4ee73 100644 --- a/libp2p/stream/lpstream.nim +++ b/libp2p/stream/lpstream.nim @@ -123,7 +123,7 @@ chronicles.formatIt(LPStream): shortLog(it) method initStream*(s: LPStream) {.base.} = if s.objName.len == 0: - s.objName = "LPStream" + s.objName = LPStreamTrackerName s.closeEvent = newAsyncEvent() s.oid = genOid() @@ -264,9 +264,9 @@ proc write*(s: LPStream, msg: string): Future[void] = method closeImpl*(s: LPStream): Future[void] {.async, base.} = ## Implementation of close - called only once trace "Closing stream", s, objName = s.objName, dir = $s.dir - s.closeEvent.fire() libp2p_open_streams.dec(labelValues = [s.objName, $s.dir]) inc getStreamTracker(s.objName).closed + s.closeEvent.fire() trace "Closed stream", s, objName = s.objName, dir = $s.dir method close*(s: LPStream): Future[void] {.base, async.} = # {.raises [Defect].} diff --git a/tests/helpers.nim b/tests/helpers.nim index 793bbc8..4cda099 100644 --- a/tests/helpers.nim +++ b/tests/helpers.nim @@ -36,7 +36,7 @@ iterator testTrackers*(extras: openArray[string] = []): TrackerBase = if not isNil(t): yield t template checkTracker*(name: string) = - var tracker = getTracker(LPChannelTrackerName) + var tracker = getTracker(name) if tracker.isLeaked(): checkpoint tracker.dump() fail() diff --git a/tests/testswitch.nim b/tests/testswitch.nim index b912a4c..b41dfdb 100644 --- a/tests/testswitch.nim +++ b/tests/testswitch.nim @@ -596,13 +596,13 @@ suite "Switch": rng = rng)) switches[0].addConnEventHandler(hook, ConnEventKind.Connected) - switches[0].addConnEventHandler(hook, ConnEventKind.Disconnected) awaiters.add(await switches[0].start()) for i in 1..5: switches.add(newStandardSwitch( privKey = some(peerInfo.privateKey), rng = rng)) + switches[i].addConnEventHandler(hook, ConnEventKind.Disconnected) onConnect = switches[i].connect(switches[0].peerInfo.peerId, switches[0].peerInfo.addrs) await onConnect @@ -627,6 +627,7 @@ suite "Switch": try: let conn = await transport.accept() discard await conn.readLp(100) + await conn.close() except CatchableError: discard @@ -712,13 +713,12 @@ suite "Switch": readers.add(closeReader()) await allFuturesThrowing(readers) + await switch2.stop() #Otherwise this leeks checkTracker(LPChannelTrackerName) checkTracker(SecureConnTrackerName) checkTracker(ChronosStreamTrackerName) - await allFuturesThrowing( - switch1.stop(), - switch2.stop()) + await switch1.stop() # this needs to go at end await allFuturesThrowing(awaiters)