vacp2p / nim-libp2p

libp2p implementation in Nim
https://vacp2p.github.io/nim-libp2p/docs/
MIT License
249 stars 54 forks source link

in yamux, do not write `{Rst}` packet to stream that's in use #1041

Closed etan-status closed 7 months ago

etan-status commented 7 months ago

When a yamux channel is reset, the connection may still be in use with pending writes. In that situation, the socket cannot be used to send the terminating {Rst} packet without corrupting the data. Waiting for the pending write to complete is also not too useful, and also would need a refactoring to even support so, as we don't track the trySend future that is currently writing, and also already purged the sendQueue.

Note that this also fixes assertions depending on chronos scheduling in local tests that use pushData on BufferStream. Because pushData checks no other pushes are in progress, tests may have randomly failed.

codecov[bot] commented 7 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 82.79%. Comparing base (6c87348) to head (73f672e).

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/status-im/nim-libp2p/pull/1041/graphs/tree.svg?width=650&height=150&src=pr&token=UR5JRQ249W&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=status-im)](https://app.codecov.io/gh/status-im/nim-libp2p/pull/1041?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=status-im) ```diff @@ Coverage Diff @@ ## unstable #1041 +/- ## ============================================ + Coverage 82.77% 82.79% +0.02% ============================================ Files 91 91 Lines 15604 15604 ============================================ + Hits 12916 12920 +4 + Misses 2688 2684 -4 ``` | [Files](https://app.codecov.io/gh/status-im/nim-libp2p/pull/1041?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=status-im) | Coverage Δ | | |---|---|---| | [libp2p/muxers/yamux/yamux.nim](https://app.codecov.io/gh/status-im/nim-libp2p/pull/1041?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=status-im#diff-bGlicDJwL211eGVycy95YW11eC95YW11eC5uaW0=) | `87.26% <100.00%> (-1.09%)` | :arrow_down: | ... and [4 files with indirect coverage changes](https://app.codecov.io/gh/status-im/nim-libp2p/pull/1041/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=status-im)