mirror of https://github.com/vacp2p/nim-libp2p.git
Handle more cancellations (#733)
* Mplex: handle write cancellation * LpChannel: Don't close connection on EOF
This commit is contained in:
parent
a7e335e1bb
commit
5d7024f2e0
|
@ -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()
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue