diff --git a/libp2p/muxers/mplex/lpchannel.nim b/libp2p/muxers/mplex/lpchannel.nim index cf1e9627a..a5a00a4ce 100644 --- a/libp2p/muxers/mplex/lpchannel.nim +++ b/libp2p/muxers/mplex/lpchannel.nim @@ -77,7 +77,6 @@ proc newChannel*(id: uint64, result.msgCode = if initiator: MessageType.MsgOut else: MessageType.MsgIn result.closeCode = if initiator: MessageType.CloseOut else: MessageType.CloseIn result.resetCode = if initiator: MessageType.ResetOut else: MessageType.ResetIn - result.writeLock = newAsyncLock() result.isLazy = lazy let chan = result @@ -178,6 +177,7 @@ method close*(s: LPChannel) {.async, gcsafe.} = s.closedLocal = true if s.atEof: # already closed by remote close parent buffer imediately await procCall BufferStream(s).close() + trace "lpchannel closed local", id = s.id, initiator = s.initiator, name = s.name, diff --git a/tests/testmplex.nim b/tests/testmplex.nim index eea99636c..138084ea3 100644 --- a/tests/testmplex.nim +++ b/tests/testmplex.nim @@ -276,11 +276,12 @@ suite "Mplex": let mplexDial = newMplex(conn) let stream = await mplexDial.newStream(lazy = true) let mplexDialFut = mplexDial.handle() - check not LPChannel(stream.stream).isOpen # assert lazy + let openState = cast[LPChannel](stream).isOpen await stream.writeLp("HELLO") - check LPChannel(stream.stream).isOpen # assert lazy await stream.close() + check not openState # assert lazy + await done.wait(1.seconds) await conn.close() await mplexDialFut @@ -387,6 +388,7 @@ suite "Mplex": check string.fromBytes(msg) == &"stream {count}!" count.inc await stream.close() + count.inc if count == 10: done.complete()