Skip to content

fix: name the pull receiver and its exit code by upstream's fork phase and error class - #8287

Merged
oferchen merged 9 commits into
masterfrom
fix/pull-trailer-role-and-daemon-exit-class
Nov 3, 2026
Merged

oferchen merged 9 commits into
masterfrom
fix/pull-trailer-role-and-daemon-exit-class

Conversation

@oferchen

@oferchen oferchen commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

Summary

A failed pull now reports from the process upstream would report from, and a daemon pull exits by error class instead of a flat 23.

A pulling upstream client receives the file list as one process (who_am_i() = Receiver). It then forks in do_recv() (main.c:1077): the child becomes the receiver (main.c:1083) and the parent the generator (main.c:1142), and each reports its own failures (rsync.c:987-995). oc runs both halves in one context. A ForkPoint marker now records when the receiver crosses that fork, and one class mapping (local_failure_error) turns a failure into upstream's report on both the remote-shell and daemon transports.

What changes:

  • Before the fork (version exchange, file list, destination root): reported as [Receiver], as the lone pre-fork client.
  • After the fork, end of stream or reset socket:
    • the receiver reports first: the whine or read error, plus its trailer;
    • the generator then whines with its own read count and exits 12 (cleanup.c:240-256: these classes send no MSG_ERROR_EXIT).
  • After the fork, --timeout: the generator times out, because check_timeout() returns early for am_receiver (io.c:256-266). The receiver then prints received SIGUSR1 (code 19), and the run exits 30.
  • After the fork, any other local code: the receiver's report is the last word.
  • A peer's exit code after the fork: the trailer names [generator], the last process to exit.
  • Generator count: the fork snapshot plus what the receiver writes it over the multiplexed error pipe (main.c:1098):
    • forwarded sub-lists: the 4-byte dir index plus every byte decoded (rsync.c:377-381, io.c:1669-1672, io.c:2167-2188);
    • NDX_FLIST_EOF (rsync.c:359);
    • one 8-byte notice per received file when inc_recurse || remove_source_files || hlinked (receiver.c:1341-1347).
  • Destination root a pull cannot create: rsync: [Receiver] mkdir "<path>" failed: <strerror> (<errno>), exit 11 (main.c:817-821). The server receiver keeps its old report, because upstream fails its change_dir#4 into the destination first (main.c:1209-1217).
  • Daemon pull exit codes:
    • before: 23 for everything without a remote code;
    • now: end of stream 12, reset socket 10 (pre-fork, [Receiver] read error: ...), --timeout 30 ([Receiver] io timeout after N seconds -- exiting), uncreatable destination root 11.

Oracle

Every expected report was printed by the tarball build of rsync 3.5.1 (/home/ofer/up351/rsync-3.5.1/rsync), never the Arch git build. Each case was compared line by line with oc.

Remote shell, fixed cut. A stub forwards exactly N bytes of the server's output, then kills it. Flat tree of three 100 KB files:

options N receiver generator rc
-r 60 14 [Receiver] (none) 12
-r 2000 1954 75 12
-r 150000 149954 83 12
-r --no-i-r 2000 / 150000 N-46 65 12
-r --no-i-r --remove-source-files 2000 / 150000 N-46 69 / 77 12
-r, two subdirs 2000 / 150000 N-46 199 / 207 12

oc matches every row.

Daemon pull. A tarball 3.5.1 daemon behind a one-shot TCP proxy cut at N bytes: EOF at 2000 gives 1905/79, at 150000 gives 149905/87. A reset at 2000 gives [receiver] read error (code 10), then the generator whine (code 12), rc 12. A replayed daemon stream (the existing daemon_pull_unexpected_close_byte_count fixture) gave every row of the new tests.

Trailer sweep (remote shell, rsync 3.5.1 server):

  • killed rsh before the handshake: [Receiver];
  • uncreatable destination root: [Receiver], 11;
  • missing source: [Receiver], 23;
  • unreadable source file: [generator], 23, also with --no-i-r.

Tests

All deterministic: every cut is a byte count, never a timer. The one exception is the --timeout arm, which waits out the client's own 1 s timeout against a daemon that never sends again.

  • crates/transfer/tests/daemon_pull_unexpected_close_byte_count.rs. The replayed daemon now waits for each client write before its next step, so a reset always lands on a client read. Arms:
    • every EOF cut, now byte-compared against 3.5.1's lines, roles included;
    • a reset before and after the fork (Linux only: other kernels may drop the bytes queued before a reset);
    • a stall under --timeout=1 before and after the fork;
    • an uncreatable destination root;
    • a received file: the replayed daemon sends all of keep once asked. The receiver reads 107 bytes either way; the generator reads 22 without --remove-source-files and 30 with it (3.5.1's numbers).
  • tests/exit_codes.rs:
    • the pre-handshake EOF arm now covers the pull, [Receiver];
    • a pull into an uncreatable destination root;
    • the trailer role of a partial pull after the fork ([generator]) and with nothing listed ([Receiver]).
  • tests/rsh_peer_eof_whine.rs: the mid-transfer pull cut now expects both processes' reports. Generator counts are not pinned over this shim: dd bs=1 dribbles bytes, so how much the client has read when it forks depends on scheduling. The first version of the per-file notice test did this and failed 1 run in 8 (73/76/82 for the same cut). The replayed-daemon test above is the deterministic pin.
  • Unit tests:
    • ForkPoint frame accounting;
    • ReportingSide roles and the generator follow-up;
    • the class mapping;
    • the receiver's sub-list and EOF forwarding;
    • the per-file notice rule.

Mutations, one per fix arm. Each was applied to the committed tree, rebuilt and run against the tests named. All 16 were killed:

arm mutation killed by
role spelling PreForkReceiver renders receiver exit_codes pull EOF, mkdir, empty-list trailer
pull role before the fork local_client_role returns Receiver exit_codes pull EOF
fork point mark_fork() removed every post-fork daemon arm
EOF marker forward forward_data(4) removed a_forked_receiver_forwards_sub_lists_and_the_eof_marker
sub-list forward forward_data(4 + n) removed same
per-file notice call note_generator_notice call removed a_received_file_costs_the_generator_one_notice_under_remove_source_files
notice rule inc_recurse dropped from the condition each_received_file_notifies_the_generator_like_upstream
generator follow-up finish() never adds it daemon EOF, reset, stall
mkdir arm arm disabled pull_into_an_uncreatable_destination_root_exits_with_file_io
daemon timeout --timeout not passed in a_silent_daemon_times_out_from_the_process_upstream_names
post-fork timeout always the local role same
read-error arm arm disabled a_reset_daemon_stream_exits_by_the_phase_it_struck
daemon fork point daemon pull always pre-fork daemon EOF, reset, stall
CLI earlier report preceding() not printed daemon EOF, reset, stall
server mkdir gate server takes the client's mkdir tag server_error_exit_code_reaches_client
ssh peer-exit role remote_exit_error(.., Receiver) pull_partial_trailer_role

Gates: cargo fmt --all --check, workspace clippy -D warnings, cargo check --target x86_64-pc-windows-gnu, targeted nextest.

Known limits

  • Unforced data-frame boundaries. The generator count assumes the receiver's forwarded data reaches the generator in one MSG_DATA frame per run between messages. Upstream also starts a new frame whenever perform_io() flushes before blocking on input, which depends on how the sender's bytes arrive. Every fixture measured stays in one frame.
  • Disk-commit timing. A file counts as received when its data has been read, which is when upstream sends the notice. A verification failure sends MSG_REDO/MSG_NO_SEND in its place, the same 8 bytes, so the model does not tell them apart.
  • Pre-buffering negotiation reads. A reset during the checksum-list read in setup_protocol() is upstream's safe_read failed to read 35 bytes (12). oc reports read error (10). The version-exchange read is already tagged (fix: exit 12 when the remote shell dies before the version exchange, as upstream #8283); the negotiation read is not.
  • Cause text. A post-fork local abort keeps oc's transfer failed: ... text: upstream prints the per-site rsyserr line, for example write failed on "%s". Only the trailer role and code changed. Task 527.
  • Connect failure. A refused connection already exits 10, but keeps oc's text and [client] role. Upstream: rsync: [Receiver] failed to connect to H (A): ... (111).
  • Peer exit code. After MSG_ERROR_EXIT upstream prints no trailer of its own (log.c, line < 0); oc still prints one, now with the phase role.
  • Wire difference. On the replayed proto-30 stream, upstream's generator sends its phase NDX_DONE right after the file request; oc had not sent it within a second.

Stack

Stacked on #8283 (task 499): the pull arm of its EOF test is this PR's, and it reuses that PR's version-exchange classifier.

Folded in

This PR now also carries #8298 (no exit trailer after the peer's MSG_ERROR_EXIT) and #8302 (handshake reset reported as safe_read, exit 12), merged into this branch so the stack lands in one CI run.

oferchen added a commit that referenced this pull request Oct 29, 2026
@oferchen
oferchen changed the base branch from fix/rsh-handshake-epipe-exit-12 to master October 30, 2026 00:34
@github-actions github-actions Bot added the bug Something isn't working label Oct 30, 2026
@oferchen oferchen closed this Oct 30, 2026
@oferchen oferchen reopened this Oct 30, 2026
A pulling upstream client forks once its file list is in (main.c:1077
do_recv()): before that it is the lone "Receiver", after it the receiver
child and the generator parent each report their own failures
(rsync.c:987-995 who_am_i()). The receiver now marks that point on a
ForkPoint, and one class mapping shared by the remote-shell and daemon
transports turns a failure into upstream's report:

- before the fork, every report names [Receiver];
- after it, end of stream and a reset socket print the receiver's report,
  then the generator's whine with its own count and exit 12, because those
  classes send no MSG_ERROR_EXIT (cleanup.c:240-256);
- a --timeout after the fork is the generator's, followed by the
  receiver's SIGUSR1 trailer (io.c:256-266);
- a peer exit code after the fork is closed by [generator].

The generator's count is the fork snapshot plus what the receiver forwards
it: sub-lists (rsync.c:377-381), NDX_FLIST_EOF (rsync.c:359) and one
notice per received file under inc_recurse, --remove-source-files or a
hard link (receiver.c:1341-1347).

A daemon pull no longer falls back to 23: end of stream exits 12, a reset
socket 10, a silent peer under --timeout 30, and a destination root the
client cannot create 11 with upstream's "mkdir ... failed" line
(main.c:817-821).
@oferchen
oferchen force-pushed the fix/pull-trailer-role-and-daemon-exit-class branch from 4be3ca9 to 4335623 Compare November 3, 2026 06:43
Upstream exits on a received MSG_ERROR_EXIT through
_exit_cleanup(val, __FILE__, 0 - __LINE__) (io.c:1930), and the
negative line keeps log_exit() quiet (cleanup.c:221-225): the peer
already reported the failure. Only a --log-file run without
--info=stats still prints the trailer. oc added its own trailer.
Before multiplexed I/O starts, upstream reads the peer through
safe_read() (io.c:351-358): a failed read() is "safe_read failed to read
%d bytes" with the length the caller asked for, then
exit_cleanup(RERR_STREAMIO). oc reported perform_io()'s "read error" and
exited 10. The handshake reads in setup_protocol now mark their I/O
failures; an end of stream or a timeout keeps its own path.
fix: print no exit trailer after the peer's MSG_ERROR_EXIT
@oferchen
oferchen merged commit c03aed7 into master Nov 3, 2026
57 of 82 checks passed
@oferchen
oferchen deleted the fix/pull-trailer-role-and-daemon-exit-class branch November 3, 2026 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant