Repository navigation
refactor(ssh): pass ssh stderr through like upstream - #8224
Merged
Merged
Conversation
upstream main.c:1356-1364 start_server() calls set_blocking(STDERR) once setup_protocol() is done, because ssh may have left fd 2 non-blocking and that loses print output when stderr is a clone of stdout. The server now does the same through fast_io::force_blocking_stderr.
upstream pipe.c:48-97 piped_child() redirects only stdin and stdout, so the remote shell writes straight to rsync's own stderr. oc captured it on a third socketpair and re-printed it line by line, which rewrote non-UTF-8 bytes to U+FFFD, held back output without a trailing newline, and printed a failed ssh's error a second time on the drop path. The child now inherits stderr. The capture channel, its drain threads and fallback warnings, the socketpair_stderr module, the async stderr drain, the ssh-socketpair-stderr feature and the captured-stderr accessors are removed.
14 of 16 tasks
13 of 15 tasks
write!/writeln! issue one write per formatted piece, and Stderr is unbuffered, so a single line such as the connection-closed message reached fd 2 as four writes. Now that the ssh child inherits the same descriptor, the remote side's output could land between them and tear the line. cli::run now wraps stderr in a line-assembling writer that emits each completed line (ending in a newline or carriage return) with one write_all, as upstream rwrite() does (log.c:269-427).
This was referenced Oct 20, 2026
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
piped_child()arranges it (pipe.c:48-97redirects only stdin and stdout). ssh's messages reach the terminal byte for byte, as soon as they are written, and exactly once.start_server()does (main.c:1356-1364).socketpair_stderrmodule, the async stderr drain, thessh-socketpair-stderrbuild feature and the captured-stderr accessors. Supersedes feat(ssh): build the socketpair stderr channel by default #8219.Details
Upstream vs oc before this change
fd_pair()socketpairs (pipe.c:57,util1.c)wire.rs)set_blocking(STDERR_FILENO)(main.c:1364)Defects the capture caused, all fixed by inheriting
wait().Removed API
SshConnection::stderr_outputandSshConnection::wait_with_stderr.SshChildHandle::stderr_outputandSshChildHandle::wait_with_stderr.AsyncSshTransport::stderr_capture.rsync_io::ssh::socketpair_stderr.AsyncStderrDrain,RingBufferandASYNC_STDERR_BUFFER_CAP.Nothing in core, cli, daemon or transfer called them; only rsync_io's own tests did.
rsync_iono longer depends ontracing.Kept unchanged
SshChildHandlereaping andmap_child_exit_status.wire.rs:66).Upstream oracle
Run on the physical Linux host against
/usr/bin/rsync3.5.1-g04355d27. Every run used a fake remote shell;-eand--rsync-pathpointed at the binary under test.Connection refused, exits 255banner:\377\376-no-newlinethen runs the servercmp)\377\376rewritten to U+FFFD-vvvPerf gate
Quiet host (load 0.47-1.95), release builds,
ssh localhost. Each case ran 9 interleaved rounds of master, branch and a master A/A copy, plus threestrace -c -ftotals per binary.-vvvEvery wall delta is under 3%, and every syscall delta is within the A/A spread.
Test plan
cargo nextest run -p rsync_io --all-features -E 'binary(ssh_stderr_child_exit)'covers four tests:wait()path;cargo nextest run --all-features -E 'binary(server_stderr_blocking)': a pull through a local remote shell, with the client's stderr pipe set non-blocking beforehand, leaves the shared stderr blocking.cargo nextest run -p fast_io --all-features -E 'test(force_blocking)':force_blocking_stderrclearsO_NONBLOCKon fd 2, in a forked child.cargo nextest run -p rsync_io -p fast_io -p core -p cli --all-features: 9611 passed.cargo nextest run -p transfer -p daemon --all-features: 5388 passed.ssh_transport,server_diagnostics_reach_client,server_stderr_blocking,/ssh/): 31 passed.cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings, the same with default features, and-p rsync_io --no-default-features.cargo check --target x86_64-pc-windows-gnu -p rsync_io -p fast_io -p transfer -p core --all-targets --all-features.cargo fmt --all -- --checkandpython3 tools/ci/check_rustfmt_all.py.python3 tools/ci/unsafe_owner_deps.py,cargo run -p xtask -- no-placeholdersandcargo run -p xtask -- citations.Coordination
Conventional commit prefix
refactor:Security considerations
ssh_stderr_child_exit.rspins byte-exact, unbuffered, exactly-once passthrough.server_stderr_blocking.rspins the post-setup blocking reset.rsync_io/src/ssh/tests.rsstill guards against an undrained stderr pipe.docs/ssh-transport.md(SSH stderr);docs/design/socketpair-stderr-channel.md, marked superseded;pipe.c:48-97andmain.c:1356-1364.Pre-merge checklist
cargo fmt --allrun locally.CHANGELOG.mdupdated if user-visible. Links use#8224, to be replaced with this PR's number.SECURITY.mdupdated if security-relevant. Not changed: no CVE or threat-model entry depends on the removed capture.Follow-up: one write per stderr line (a7834cc)
CI (
Linux musl (nightly)) caughtrsh_peer_eof_whinereading: connection unexpectedly closed ...with itsoc-rsyncprefix torn off.writeln!on the unbufferedStderrissues one write per formatted piece: strace showed the line leaving as four writes (oc-rsync,:, the message,\n). With the ssh child now sharing fd 2, the remote side's output landed between them.cli::runnow wraps stderr inlogging_sink::LineAtomicWriter. It emits each completed line, ending in\nor\r, with a singlewrite_all, as upstreamrwrite()does (log.c:269-427).rsh_peer_eof_whine, 50 runs under load-avvv --msgs2stderr, 200 files,writesyscallscli::runwithout the wrapcli/tests/stderr_whole_line_writes.rstests red