Repository navigation
Conversation
Splice keeps references to the input pages, so a pipe and a file can observe different bytes if those pages change before the pipe is read. Keep splice for a single output. With two or more outputs, read one buffer and write that buffer to each of them.
|
GNU testsuite comparison: |
Contributor
|
One write code is more simple. Would you do something like instead? |
oech3
reviewed
Oct 31, 2026
Comment on lines
+162
to
+165
| // One output can be spliced: there is no second copy for a later change | ||
| // of the input pages to disagree with. Two or more outputs must share | ||
| // one userspace buffer, because splice and tee keep references to the | ||
| // input pages and each output would materialise them at a different time. |
Contributor
There was a problem hiding this comment.
Suggested change
| // One output can be spliced: there is no second copy for a later change | |
| // of the input pages to disagree with. Two or more outputs must share | |
| // one userspace buffer, because splice and tee keep references to the | |
| // input pages and each output would materialise them at a different time. | |
| // splice is restricted to one writer since input's page caches can be changed after writing to 1st writer. |
Please make the comment simpler.
Contributor
There was a problem hiding this comment.
By the way, if kernel added SPLICE_F_FORCE_COPY to splice, or there is a low-cost way to reflesh memfd, we can use it for draining input and keep zero-copy at other places to change 2 memcpy to 1 memcpy.
oech3
reviewed
Oct 31, 2026
Comment on lines
+846
to
+851
| /// Splice keeps references to the input pages. With a file and a pipe, those | ||
| /// pages can change after tee exits and before the pipe is read, so the two | ||
| /// outputs would disagree. Both must keep the bytes tee actually read. | ||
| #[test] | ||
| #[cfg(unix)] | ||
| fn test_tee_file_and_stdout_keep_the_bytes_that_were_read() { |
Contributor
There was a problem hiding this comment.
Suggested change
| /// Splice keeps references to the input pages. With a file and a pipe, those | |
| /// pages can change after tee exits and before the pipe is read, so the two | |
| /// outputs would disagree. Both must keep the bytes tee actually read. | |
| #[test] | |
| #[cfg(unix)] | |
| fn test_tee_file_and_stdout_keep_the_bytes_that_were_read() { | |
| #[test] | |
| #[cfg(unix)] | |
| fn test_tee_file_and_stdout_keep_the_bytes() { |
Different reason an be added in the future.
oech3
reviewed
Oct 31, 2026
|
|
||
| let scene = TestScenario::new("tee"); | ||
| let at = &scene.fixtures; | ||
| let original = vec![b'a'; 32 * 1024]; |
Contributor
There was a problem hiding this comment.
Would you use 1 MiB 'aaa...' + 64KiB 'bbb...' (then original is 1024 + 64 KiB).
Contributor
|
Did you accidentally closed?
|
Contributor
|
I Co-authored your noreply addr in #16204 . |
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.
Summary
tee FILEon Linux splices the input, so standard output andFILEcan end up with different bytes if the input pages change before the pipe is read. Fixes tee: zero-copy lets stdout and FILE differ if input changes after tee exits #15803.teeexits and checks that standard output and the file both still hold the original bytes.Test plan
cargo test --test tests test_teeon macOS (16 tests, including the new one)cargo check -p uu_tee --target x86_64-unknown-linux-gnutee snapshot < upload | catafter an in-place rewrite ofupload, with both outputs identical