From 1d16d22f5f071a1046800c87ee0978384b9b368c Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Mon, 23 Nov 2020 09:07:11 -0600 Subject: [PATCH] Don't allow concurrent pushdata (#444) * handle resets properly with/without pushes/reads * add clarifying comments * pushEof should also not be concurrent * move channel reset to bufferstream this is where the action happens - lpchannel merely redefines how close is done Co-authored-by: Jacek Sieka --- libp2p/muxers/mplex/lpchannel.nim | 28 +------- libp2p/stream/bufferstream.nim | 49 +++++++++++--- libp2p/stream/lpstream.nim | 1 + tests/testbufferstream.nim | 71 +++++++++++++------- tests/testmplex.nim | 103 ++++++++++++++++++++++-------- 5 files changed, 170 insertions(+), 82 deletions(-) diff --git a/libp2p/muxers/mplex/lpchannel.nim b/libp2p/muxers/mplex/lpchannel.nim index cc37083..f577f63 100644 --- a/libp2p/muxers/mplex/lpchannel.nim +++ b/libp2p/muxers/mplex/lpchannel.nim @@ -80,32 +80,11 @@ proc reset*(s: LPChannel) {.async, gcsafe.} = return s.isClosed = true + s.closedLocal = true trace "Resetting channel", s, len = s.len - # First, make sure any new calls to `readOnce` and `pushData` etc will fail - - # there may already be such calls in the event queue however - s.closedLocal = true - s.isEof = true - s.readBuf = StreamSeq() - s.pushedEof = true - - let pushing = s.pushing # s.pushing changes while iterating - for i in 0..