Skip to content

fix(daemon): exit 4 on a refused option, not 1 - #7563

Merged
oferchen merged 1 commit into
masterfrom
fix/daemon-refusal-exit-code
Aug 28, 2026
Merged

oferchen merged 1 commit into
masterfrom
fix/daemon-refusal-exit-code

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Problem

A daemon that refuses a client-requested option terminated the peer with
MSG_ERROR_EXIT carrying RERR_SYNTAX (1). Upstream reports
RERR_UNSUPPORTED (4).

Upstream

clientserver.c:1254-1268 is upstream's single post-@RSYNCD: OK fatal
branch:

	if (!ret || err_msg) {
		if (err_msg) { ... } else
			option_error();
		msleep(400);
		exit_cleanup(RERR_UNSUPPORTED);      /* clientserver.c:1267 */
	}

!ret is parse_arguments() failing, which is where a refused option lands
(options.c:2041-2043 -> create_refuse_error(opt) -> goto cleanup).
err_msg is a failed pre-xfer exec. Both arms exit 4. --write-devices
and --copy-devices reach that branch because a daemon seeds them into the
refuse list unconditionally (options.c:1057-1059
parse_one_refuse_match(0, "write-devices", list_end)).

RERR_UNSUPPORTED is used for many unrelated refusals upstream, so the
constant name alone is not the argument - the citation above is the specific
site, confirmed by measurement below.

Measured, pinned upstream 3.5.0 daemon vs oc daemon, same client

Same upstream 3.5.0 client against each daemon in turn; push direction (a
pull never forwards --write-devices, options.c:3150 gates it on
am_sender).

cell upstream rc oc rc before oc rc after
--write-devices (push) 4 1 4
refuse options = compress, -z (push) 4 1 4
refuse options = delete, -r --delete (push) 4 1 4
--copy-devices (pull) 10 1 4
refuse options = compress, -z (pull) 10 1 4
read-only push 1 1 1
write-only pull 1 1 1

The pull rows are a client-side race inside upstream, not a daemon
divergence: upstream's receiver prints the refusal text (so it read
MSG_ERROR_XFER) and then loses to the RST, exiting
RERR_SOCKETIO at io.c(907) before it can honour MSG_ERROR_EXIT. The
daemon's own code is 4 in both directions. This change does not chase that
race.

Scope

Only the exit code. The @ERROR: payload prefix (upstream writes
rsync: The server is configured to refuse ...) is a separate divergence and
is deliberately left alone - it is a different argument to
send_multiplexed_error_and_exit, and the measurement above confirms it is
unchanged on both sides of the fix. The absent
rsync error: requested action not supported (code 4) at clientserver.c(1267)
summary line is part of that same payload divergence and is likewise untouched.

Class, not a one-off

Three post-OK multiplexed abort sites exist in
module_access/request.rs:

site upstream decision code before code after
handle_refused_option_post_handshake clientserver.c:1267 1 4
handle_client_arg_rejection_post_handshake clientserver.c:1267 4 4 (already correct)
handle_access_denied_post_handshake main.c:934 / main.c:1167 exit_cleanup(RERR_SYNTAX) 1 1 (correct, unchanged)

The first two are the same upstream branch; the refused-option arm was the
straggler and this makes the branch uniform. The read-only/write-only
rejection is a genuinely different decision made later in
do_server_recv() / do_server_sender() and keeps RERR_SYNTAX.

Tests

run_daemon_post_ok_refused_option_uses_multiplexed_error and
run_daemon_refusal_lingers_so_the_peer_can_read_it now pin the
MSG_ERROR_EXIT payload at RERR_UNSUPPORTED_EXIT_CODE. Both fail on the
pre-fix source (left: 1, right: 4) and pass after. The linger test's own
header already cited exit_cleanup(RERR_UNSUPPORTED) while asserting 1, so
that assertion was drifting from its own citation.

refuse_emits_msg_error_xfer_post_handshake uses the constant on both sides
of its comparison, so it is a framing test rather than a policy test; its
fixture is moved to 4 so it keeps modelling the real refusal.

Mutating the fix back reddens exactly those two tests and leaves the
read-only/write-only companions green.

A daemon that refuses a client option sent the peer MSG_ERROR_EXIT with
RERR_SYNTAX (1). Upstream ends that path in exit_cleanup(RERR_UNSUPPORTED)
at clientserver.c:1267, so a client scripting on `rsync -z` (or the
default-refused --write-devices / --copy-devices) being rejected saw 1
where upstream reports 4.

Measured against the pinned upstream 3.5.0 daemon, same client, push
direction:

  --write-devices    upstream 4, oc 1 -> 4
  refuse options=compress, -z    upstream 4, oc 1 -> 4
  refuse options=delete, -r --delete    upstream 4, oc 1 -> 4

Upstream has one post-@rsyncd:OK fatal branch (clientserver.c:1254-1268,
`if (!ret || err_msg)`), which covers both a refused option and a failed
pre-xfer exec and ends in RERR_UNSUPPORTED. The sibling on that branch,
handle_client_arg_rejection_post_handshake, already sent 4; the refused-
option arm was the straggler, so this makes the branch uniform. The
read-only push and write-only pull rejections are a different decision -
made later in do_server_recv()/do_server_sender() - and keep RERR_SYNTAX;
their tests stay green unchanged.

The `@ERROR: ` payload prefix on the refusal text is untouched: the exit
code is a separate argument to send_multiplexed_error_and_exit, and the
prefix divergence is owned elsewhere.
@github-actions github-actions Bot added the bug Something isn't working label Aug 28, 2026
@oferchen
oferchen merged commit b59d527 into master Aug 28, 2026
72 checks passed
@oferchen
oferchen deleted the fix/daemon-refusal-exit-code branch August 28, 2026 12:25
@oferchen
oferchen restored the fix/daemon-refusal-exit-code branch September 1, 2026 08:22
@oferchen
oferchen deleted the fix/daemon-refusal-exit-code branch September 1, 2026 14:37
oferchen added a commit that referenced this pull request Sep 2, 2026
`## [Unreleased]` last covered the #7304-#7522 era. Measured against the 60
most recently merged pull requests, 44 were absent; of the most recent 45,
43 were absent. Nothing from #7574 onward was recorded at all.

Each entry is derived from what the pull request actually landed - the merge
commit and the body - not from its title. Three cases where those differ:

  * #7616 ships far more than the doc-alias correction its body describes:
    the `upstream_version` pin moves to 3.5.0 and `--version` starts naming
    `quic`, `sd-notify`, `vmsplice` and `send_zc`.
  * #7618 also adds the pull-request rustdoc-link job its body says was
    filed separately, which is what closes the master-only-gate recurrence.
  * #7602's squash carries the closed #7597 as its first commit, so the
    directory-obstacle half is recorded under #7602.

#7587 is deliberately not recorded. Its merge commit is empty: the change
had already landed as #7563, which the section already names.

Entries extend the existing Keep a Changelog groups and the bold
sub-groupings. Clusters that are one story carry one entry with several
references: the FERROR_XFER routing and its two-phase drain (#7576, #7581),
the connection-FSM close edge and the accept loop that outlives a session
error (#7579, #7590), the three detaching daemon suites (#7578, #7588,
#7592), the io_uring and SEND_ZC work (#7593, #7600, #7610), the citation
retargets (#7601, #7603, #7604), and the accept-loop pin flake (#7615,
#7620).

Only `## [Unreleased]` is touched; every released section, including the
3.4.4 statements that were correct when written, is byte-identical.
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