Repository navigation
fix: echo MSG_ERROR_EXIT and wait for the peer as rsync 3.5.1 does - #8357
Merged
Merged
Conversation
oferchen
force-pushed
the
fix/error-exit-echo-drain
branch
2 times, most recently
from
November 10, 2026 20:36
23f8500 to
524c90c
Compare
5 tasks done
oferchen
force-pushed
the
fix/error-exit-echo-drain
branch
from
November 11, 2026 06:14
b7eaa5d to
917bf45
Compare
oferchen
force-pushed
the
fix/error-exit-echo-drain
branch
2 times, most recently
from
November 11, 2026 08:54
b36e0d1 to
4f787ee
Compare
oferchen
force-pushed
the
fix/error-exit-echo-drain
branch
from
November 11, 2026 10:31
4f787ee to
5b5b606
Compare
oferchen
force-pushed
the
fix/error-exit-echo-drain
branch
from
November 11, 2026 10:49
5b5b606 to
b63a0f0
Compare
A process that receives its peer's MSG_ERROR_EXIT now answers as io.c:1892-1930 read_a_msg() does. An empty frame is answered by the not-yet-forked receiver. From protocol 31, a code is answered with the code by a forked receiver and with an empty frame by anyone else. After either side's fatal error, over a daemon socket, it then waits for the peer to close (cleanup.c:242-253, io.c:1066-1085 noop_io_until_death). The wait answers a further frame, is bounded by --timeout or 60 s, and prints upstream's read error and io timeout lines if it fails. A peer's RERR_PARTIAL (23) now ends the transfer like any other code instead of being deferred. The daemon refused lines behind it are read during the wait. An aborting MSG_ERROR_EXIT no longer leaves its 4-byte payload in the reader's buffer as data. Task 232.
On a client, 3.5.1's _exit_cleanup() calls log_exit() before noop_io_until_death() (cleanup.c:221-253). So when the wait for the daemon's exit fails, its `read error` or `io timeout` line comes after the `rsync error:` trailer of the failure that started it. oc printed the wait's line from inside the transfer, before core built the trailer. The transfer now carries the failed wait out behind the error that ended it. Core splits the two apart, classifies the error as before, and attaches the wait's line to the report. The CLI prints that line after the trailer: with the program-name prefix for a read error (log.c:483-500), and as-is for a timeout. Task 639.
oferchen
force-pushed
the
fix/error-exit-echo-drain
branch
from
November 11, 2026 11:01
b63a0f0 to
34594cd
Compare
oferchen
added a commit
that referenced
this pull request
Nov 13, 2026
## Summary Below protocol 29, a 3.5.1 server over a remote shell clears `msgs2stderr` (compat.c:653-654). rwrite() then queues every FERROR line for the client (log.c:357-367 -> io.c:1088 send_msg()), and none reaches the server's own stderr. oc's `--server` always wrote its fatal report to stderr. So when a client refuses `-FF` at protocol 28 and exits, oc showed an extra line from the server: `oc-rsync error: server error: failed to fill whole buffer (code 12) ... [server=...]`. 3.5.1 shows nothing from the server; strace of the 3.5.1 server shows no write to fd 2 before exit_group(12). - **Transfer.** A new `queue_fatal_report` queues the fatal report as message frames whenever the server frames its error lines (`ServerWriter::frames_errors`, the same route rwrite() uses). It skips the queue when the exit is one the peer asked for (cleanup.c:221-226). The queued lines leave only with `announce_error_exit`'s flush. So for a transport-class code, or below protocol 31, they never reach the wire (cleanup.c:241-253), matching 3.5.1. The line-sending that used to live inside `announce_error_exit` moves here. A socket daemon takes this same path, with the same output as before. - **`--server` (cli).** It hands the transfer a report hook, `run_server_fds(.., fatal_report)`. When the hook was used, the server does not print its report again and still exits with the same code. The generator-EOF report from #8352 follows the same rule: it is printed only when messages are not framed. ## Verification - **New test, `transfer/tests/server_framed_fatal_report.rs`, push and pull, lsh stub, `--protocol=28 -FF`.** - CI cell (oc client, oc server): stderr carries exactly one `error:` trailer, the client's code-2 one, and exit is 2. - Oracle cell (runs when `OC_RSYNC_UPSTREAM_BIN_3_5_1` is set): with a 3.5.1 client, an oc server and a 3.5.1 server produce identical stderr and exit status. - **Unit tests in `tests/error_exit_gate.rs`:** - a report bound for stderr (protocol 29+) is left to the caller; - a framed report for RERR_STREAMIO at protocol 28 is rendered but never written; - an exit the peer asked for renders no report; - the existing report-before-exit-frame cell now goes through `queue_fatal_report`. - **Mutations, each killed:** - M1, never queue the report: 4 cells fail. - M2, frame on every route: 1 cell fails. - M3, the server prints even when the report was framed: both e2e cells fail. - nextest -p transfer/core/cli/daemon: 12433 passed, 86 skipped (oracle cells included). clippy, fmt, no-placeholders and dead-code census clean. ## Residuals - The Windows `--server` path (`run_server_stdio`) takes no report hook yet, so at protocol 28 on Windows it still prints the report to its own stderr. - #8357 adds a drain after the error exit. If that drain flushes the queued message buffer, a transport-class failure would push these queued lines onto the wire, which upstream never does. The two PRs must be checked together.
oferchen
added a commit
that referenced
this pull request
Nov 14, 2026
#8372) ## Summary Stacked on #8367. A client whose transfer fails now leaves the way rsync 3.5.1's `_exit_cleanup()` does: - It polls the remote shell once with WNOHANG (cleanup.c:146-154) and takes the shell's status only if the shell has already exited. - If the shell is still running, it sends it SIGUSR1, as `kill_all(SIGUSR1)` does (cleanup.c:201-202, util1.c:692-709), and exits without waiting. Before, oc closed both pipes and blocked in `wait()`, so a remote shell that ignored end-of-file held the client open until the shell exited by itself. A transfer that finishes still waits for the child, as `wait_process_with_flush()` does (main.c:198-227, :1179, :1454). Because the client now signals its remote shell, an rsh server has to write its fatal report before telling the client it is exiting, or the signal can cut the report off. 3.5.1 writes the cause line at the error site and `log_exit()`'s trailer at cleanup.c:221-224, both on stderr (`msgs2stderr = 2`, options.c:103, log.c:357), before `MSG_ERROR_EXIT` goes out at cleanup.c:240-256. oc's rsh server wrote both after the transfer returned, so after the frame. A 3.5.1 client, which signals its rsh child, lost the oc server's trailer 3 of 3 times. ## Changes **Commit 1: poll and signal** - `rsync_io`: new `SshChildHandle::poll_exit()`. It calls `try_wait` once. If the child is still running, it sends SIGUSR1 on Unix and releases the child unreaped. - `platform::signal::send_sigusr1()`: a safe `nix` `kill(2)` wrapper, with a unit test. - `core` ssh drive: the handshake-failure path and the transfer-failure path both use `poll_cleanup_child()`. - A `waitpid` that fails, or finds the child still running, leaves the local code standing. It no longer becomes `RERR_WAITCHILD` (21). - #8352's early read-side close on a failed transfer is removed. It existed only so the blocking wait could return, and that wait is gone (cleanup.c:146-154). Mutant M1 below shows #8352's own cells catch a wait put back there. - `transfer_failure_error` now takes `Option<ExitCode>`. The embedded transport passes its exit report. **Commit 2: one fatal-report hook (on #8367)** - #8367 adds the `FatalReport` hook. The transfer now routes its lines the way `rwrite()` routes each message: - frames them when `frames_errors()` is true; - otherwise writes them to the server's own stderr. - Either way this happens before `announce_error_exit`. - `queue_fatal_report` is renamed `report_fatal_failure`. - cli `run.rs`: one `server_fatal_report()` renders the lines, including #8352's generator-EOF case, and computes the exit code. A `OnceLock` records that the hook ran, and the post-return path then prints nothing. A failure before the transfer body starts is still reported after it returns. ## Oracle (3.5.1 tarball build, host) - Remote-shell stub that traps SIGUSR1, closes its stdout and sleeps 30 s without holding stderr: - 3.5.1, push and pull: rc 12, the two client lines, the stub's "got SIGUSR1" line, 0 s. - oc before: blocks until the 30 s cap; the stub is never signalled. - oc after: identical to 3.5.1. - Push into /dev/full over a shim that execs the server directly, 3 runs per pair. Results before this change: | client / server | cause line | trailer | |---|---|---| | 3.5.1 / 3.5.1 | 3/3 | 3/3 | | 3.5.1 / oc | 3/3 | 0/3 | After this change, 3.5.1 / oc prints both lines 3/3. - WNOHANG races the shell's exit in 3.5.1 too: - `-e "sh -c 'exit 255'"`: exit 255 in 18/30 runs, 12 in 12/30. - Real ssh with a missing `--rsync-path`: 12 in 12/12. - Shell exiting 127 after reading the greeting: 127 in 20/20 unloaded. - Twin of `push_cut_inside_the_goodbye`, 3.5.1 at both ends: - Unloaded, 12/12 runs: only the client's two lines. - Under 6-way load, 22/72 runs also show the 3.5.1 server's own lines on the shared stderr: `[generator] write error: Broken pipe (32)` with a code 10 trailer, or `connection unexpectedly closed ... [generator]` with a code 12 trailer. ## Tests - New `exit_codes::exit_code_12_stream_io::remote_shell_ignoring_eof_is_signalled_not_waited_for`, push and pull. - The stub's trap line reaches the captured stderr only if the client signalled the stub. - The stub holds no stderr while it sleeps, so a client that waits instead fails after the cap. The test makes no time-based assertion. - `receiver_write_failure`: - The 3.5.1-client push to an oc server now asserts the trailer on 3 of 3 runs. - New oracle cell: a 3.5.1 push to a 3.5.1 server. - Three cells asserted a child status that 3.5.1 itself only reports when the poll wins the race. Each now accepts 3.5.1's two outcomes, and the trailer must name the code that won. The deterministic fold stays pinned by the `version_exchange` unit test. - `ssh_transfer::ssh_stderr_not_reappended_to_error_message`: 255 or 12. - `ssh_transfer::ssh_rsync_path_not_found`: 12 or 127. - `rsh_peer_eof_whine::a_worse_remote_shell_status_keeps_the_whine_and_names_its_own_code`: 127 or 12. - `rsh_peer_eof_whine`: - The `push_cut_after` shim's `dd` ignores SIGUSR1 and keeps a copy of the client's stderr, so its tally is always written before the output is read. - `push_cut_inside_the_goodbye` filters lines tagged with a server role (`[generator]`, `[receiver]`, or a `[generator=` / `[receiver=` / `[server=` trailer), matching the 3.5.1 oracle above. The client's two lines are still asserted exactly. - #8367's `a_report_bound_for_stderr_is_left_to_the_caller` becomes `a_report_bound_for_stderr_is_rendered_but_not_framed`: the stderr route renders the report, and only the exit frame reaches the wire. ## Mutants (each failed the named cells) - M1, a failed transfer waits for the shell again, without #8352's close: `compression_desync_exit` pull cells (2/2). - M2, the stderr route writes nothing: `receiver_write_failure` rsh push and 3.5.1-client push (2). - M3, no SIGUSR1: `remote_shell_ignoring_eof_is_signalled_not_waited_for`. - Hook call dropped (on the earlier version of this change): the 3.5.1-client order cell. ## Verification (host, at 937298b) - `check_rustfmt_all.py`: clean. `cargo clippy --workspace --all-targets --all-features --no-deps -D warnings`: clean. - nextest, the binaries this touches (`compression_desync_exit`, `receiver_write_failure`, `server_framed_fatal_report`, `exit_codes`, `rsh_peer_eof_whine`, `ssh_transfer`, plus `error_exit_gate`, `send_sigusr1`, `transfer_failure_error`, `cleanup`): 170/170. - `rsh_peer_eof_whine`, 4 further runs: 20/20. An earlier 6-way load stress of the same binary (filter matching the role tag at line end only) passed 48/48. The final filter only drops more server-role lines. ## Residuals - Upstream polls the child before the MSG_ERROR_EXIT drain (cleanup.c:146 precedes :240-256). oc polls after the transfer returns, which after #8357 is after the drain. The code is the same unless the remote's exit status differs from the echoed code. - `local_failure_error` keeps its peer-went-first filter for the embedded transport, whose exit report arrives only after the session closes. - Windows: a still-running child is released without a signal. Cygwin's mapping of SIGUSR1 onto a native ssh.exe was not measured.
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
Ports rsync 3.5.1's handling of a received
MSG_ERROR_EXITand its wait for the peer's exit.!am_sender && !am_generator).MSG_ERROR_EXITis answered the same way, and EOF is a quiet exit (io.c:828).--timeout, or 60 s when none is set (io.c:1080-1081).rsync: [who] read error: strerror (errno)(io.c:918-925, who_am_i() rsync.c:987-995).[who] io timeout after N seconds -- exiting(io.c:261-262).MSG_ERROR_EXIT(23)and keep reading, so the client could exit 0; 3.5.1 has no such case. Every code now ends the transfer. Thedaemon refusedlines sent after the frame are read and printed during the wait, as 3.5.1 does.MSG_ERROR_EXITaborts a read. Before, the next read returned those 4 bytes as data.Evidence
All cells were measured on the host against the 3.5.1 tarball build.
Replayed daemon. The daemon sends
MSG_ERROR_EXITin place of the file list and records every byte the client writes back. 3.5.1 and oc produce identical bytes and exit codes in all 16 cells:These cells are pinned by
a_peer_error_exit_is_answered_as_upstreams_receiver_answers_it(crates/transfer/tests/daemon_pull_unexpected_close_byte_count.rs), which keys on frame bytes and the close, not on time.Live daemon (destination-root mkdir failure, push and pull, both implementations on both sides, straced):
[sender] read error: Connection reset by peer (104).Sender-originated case. There is no live fixture: 3.5.1 fails
--files-frombefore multiplexing, and--max-allocdid not trigger. Instead, unit wire tests incrates/transfer/src/error_exit.rsdrive eachExitReaderrole throughprotocol::send_msgframes and assert the answer bytes.daemon-filter-push-direction: 3.5.1 and oc clients against 3.5.1 and oc daemons, 5 runs each. All 20 runs give rc 23, the same
daemon refusedlines and the same files as 3.5.1.Mutants (6/6 killed):
Each is killed by
a_peer_error_exit_is_answered_as_upstreams_receiver_answers_itand/or the role-specific unit tests (a_code_is_answered_by_role_from_protocol_31,echo_follows_read_a_msg,waiting_follows_exit_cleanup,check_error_exit_aborts_on_rerr_partial,multiplex_reader_exit_23_aborts_and_the_late_error_xfer_is_read_after,the_unforked_receiver_answers_the_peers_empty_frame_and_stops).Residuals
--no-msgs2stderrover rsh: 3.5.1 also waits there (io.c:1073-1075). oc waits only over a daemon socket.rsync error:trailer. 3.5.1 prints the trailer first (cleanup.c:221-225). Task 639.transfer failed to HOSTlog line.Test plan
python3 tools/ci/check_rustfmt_all.pytransfercargo nextest run -p transfer --all-features(reader, multiplex, error_exit, daemon_pull_unexpected_close_byte_count): 299 passedcargo nextest run -p daemon -p core --all-features(error-exit, filter, refuse, remote_exit, partial, exit_code): 558 passed