Repository navigation
fix(tcp): keep a partial active line across re-arm and passive recv - #108
Merged
Merged
Conversation
Programs using line mode now get the whole line after pausing and resuming message delivery, or after switching to reading it directly. This also holds when the program resumes delivery while it is still turned on. The lost beginning no longer shows up stuck to the front of a later line. When a program switches the connection from lines to raw bytes, it reads those waiting bytes first; a line cut off by the other side closing is still dropped, as in Erlang/OTP. A new test checks nine such cases in Nera and in Erlang/OTP.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Programs that read a TCP connection line by line could lose the beginning of a line: if Nera had already received part of the line when the program paused message delivery, the rest arrived later without that part, while Erlang/OTP keeps the line whole.
What changed
Before and after
Before: When abc had arrived, delivery was paused, and def plus a newline came next, Nera handed the program def and the newline, where Erlang/OTP 29 hands over abcdef and the newline; 7 of 9 test cases differed from Erlang/OTP 29.
After: The same program now gets abcdef and the newline either way, and all 9 test cases match Erlang/OTP 29 byte for byte.
Only the bytes a program receives change, with no screen to show; a side-by-side run of Erlang/OTP 29, the previous build and this build stands in.
Checked
How it was checked
cargo clippy --workspace --all-targets --locked -- -D warnings: clean
cargo test --workspace --locked --no-fail-fast: 2,303 passed, 0 failed, 1 ignored
nera test -j 1 --timeout 30: 559 passed, 0 failed, 2 skipped (the OneCached exclusions) of 561
nera test 'tcp_*' -j 1 --timeout 30, three runs: 19 of 19 each
scripts/test-allocator-config.py and scripts/test-stacktrace-order.py: pass
tcp_line_partial on Erlang/OTP 29.1.2 with the inet and socket backends: passes three times each
The fix sets {active, false} and {packet, raw} to move a buffered partial line in front of the bytes later reads take first, and makes the line-mode setopts read start from that partial line.
Risk
Risk: low in every dimension.
Full risk assessment
Not done
On Windows, where Nera reads connections without its event loop, nothing changed and nothing was run; that reader keeps reading a line it has begun after delivery is paused, as the known limits now say.
Switching a connection that still delivers messages from lines to raw bytes hands over the waiting bytes only when more data arrives; Erlang/OTP 29's socket backend does the same, while its default backend hands them over at once.