diff --git a/libp2p/muxers/mplex/lpchannel.nim b/libp2p/muxers/mplex/lpchannel.nim index 46f558049..eb7d6ca14 100644 --- a/libp2p/muxers/mplex/lpchannel.nim +++ b/libp2p/muxers/mplex/lpchannel.nim @@ -78,6 +78,8 @@ proc open*(s: LPChannel) {.async, gcsafe.} = try: await s.conn.writeMsg(s.id, MessageType.New, s.name) s.isOpen = true + except CancelledError as exc: + raise exc except CatchableError as exc: await s.conn.close() raise exc @@ -221,6 +223,11 @@ proc completeWrite( libp2p_protocols_bytes.inc(msgLen.int64, labelValues=[s.tag, "out"]) s.activity = true + except CancelledError as exc: + # Chronos may still send the data + raise exc + except LPStreamClosedError as exc: + raise exc except CatchableError as exc: trace "exception in lpchannel write handler", s, msg = exc.msg await s.reset() diff --git a/libp2p/protocols/secure/secure.nim b/libp2p/protocols/secure/secure.nim index 3eae7dce7..b68b5b14c 100644 --- a/libp2p/protocols/secure/secure.nim +++ b/libp2p/protocols/secure/secure.nim @@ -152,6 +152,8 @@ method readOnce*(s: SecureConn, s.isEof = true await s.close() raise err + except CancelledError as exc: + raise exc except CatchableError as err: debug "Error while reading message from secure connection, closing.", error = err.name, diff --git a/libp2p/stream/bufferstream.nim b/libp2p/stream/bufferstream.nim index 6d31d3a5d..56f3151fa 100644 --- a/libp2p/stream/bufferstream.nim +++ b/libp2p/stream/bufferstream.nim @@ -134,6 +134,10 @@ method readOnce*(s: BufferStream, let buf = try: await s.readQueue.popFirst() + except CancelledError as exc: + # Not very efficient, but shouldn't happen often + s.readBuf.assign(@(p.toOpenArray(0, rbytes - 1)) & @(s.readBuf.data)) + raise exc except CatchableError as exc: # When an exception happens here, the Bufferstream is effectively # broken and no more reads will be valid - for now, return EOF if it's