Skip to content

Commit

Permalink
Avoid closing connection on channel EOF (#816)
Browse files Browse the repository at this point in the history
  • Loading branch information
etan-status authored Jan 6, 2023
1 parent 9f658c1 commit ba45119
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 5 additions & 1 deletion libp2p/muxers/mplex/lpchannel.nim
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,11 @@ proc completeWrite(
except CancelledError as exc:
# Chronos may still send the data
raise exc
except LPStreamClosedError as exc:
except LPStreamConnDownError as exc:
await s.reset()
await s.conn.close()
raise exc
except LPStreamEOFError as exc:
raise exc
except CatchableError as exc:
trace "exception in lpchannel write handler", s, msg = exc.msg
Expand Down
10 changes: 8 additions & 2 deletions libp2p/muxers/mplex/mplex.nim
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,14 @@ method handle*(m: Mplex) {.async, gcsafe.} =
raise newLPStreamLimitError()

trace "pushing data to channel", m, channel, len = data.len
await channel.pushData(data)
trace "pushed data to channel", m, channel, len = data.len
try:
await channel.pushData(data)
trace "pushed data to channel", m, channel, len = data.len
except LPStreamClosedError as exc:
# Channel is being closed, but `cleanupChann` was not yet triggered.
trace "pushing data to channel failed", m, channel, len = data.len,
msg = exc.msg
discard # Ignore message, same as if `cleanupChann` had completed.

of MessageType.CloseIn, MessageType.CloseOut:
await channel.pushEof()
Expand Down

0 comments on commit ba45119

Please sign in to comment.