Skip to content

fix(daemon): drain peer goodbye without half-close to unblock UTS-v3 cluster A - #5765

Merged
oferchen merged 2 commits into
masterfrom
fix/uts-v3-a-shutdown-race
Jun 14, 2026
Merged

oferchen merged 2 commits into
masterfrom
fix/uts-v3-a-shutdown-race

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Root cause: oc-rsync daemon-as-sender called shutdown(SHUT_WR) immediately after the engine returned, sending FIN before the receiver had a chance to write its trailing MSG_STATS + NDX_DONE through the receiver-to-generator pipe. The receiver saw FIN, abandoned its writes, and emitted connection unexpectedly closed (N bytes received so far) [receiver]. The four upstream UTS-v3 cluster A failures (batch-mode, alt-dest, daemon-gzip-download, daemon-refuse-compress) all clustered near the daemon's last write because the cutoff byte count = exactly the bytes the daemon sent before the half-close.

  • Fix: drop the half-close. Keep SO_LINGER(5s) so the daemon's TX bytes reach the peer before close() returns, and drain reads in a loop until peer FIN (EOF), bounded at 5s. Mirrors upstream's fork-model behaviour (cleanup.c:close_all() is a no-op on Linux without SHUTDOWN_ALL_SOCKETS; the kernel handles cleanup once the sender child exits) and the noop_io_until_death() drain pattern (io.c:943).

  • Verification: rebuilt on Linux/aarch64 from master + this fix, ran the upstream rsync 3.4.3 testsuite (--rsync-bin=rsync --rsync-bin2=oc-rsync --use-tcp) for the four cluster A tests. All 4 pass. Wire-byte capture (strace -ff -y on the daemon worker) before/after confirms the daemon now drains the receiver's trailing 20-byte goodbye instead of closing on the first 5 bytes.

Test plan

  • cargo nextest run -p daemon --all-features -E 'test(daemon_compress_pull_drains_peer_goodbye)' - new regression test passes locally
  • cargo nextest run -p daemon --all-features -E 'test(daemon_compress_push) | test(daemon_pull_lifecycle) | test(daemon_push_then_pull) | test(daemon_compress_pull) | test(run_daemon_post_ok)' - adjacent daemon tests pass locally
  • Upstream UTS-v3 cluster A scenarios pass: daemon-gzip-download, daemon-refuse-compress, batch-mode, alt-dest (verified on Linux/aarch64 against upstream rsync 3.4.3)
  • CI: fmt+clippy, nextest stable (full), Windows, macOS, Linux musl

@github-actions github-actions Bot added the bug Something isn't working label Jun 14, 2026
oferchen added 2 commits June 14, 2026 11:22
…cluster A

UTS-v3 Cluster A: 4 upstream testsuite failures (batch-mode, alt-dest,
daemon-gzip-download, daemon-refuse-compress) all surface as
"connection unexpectedly closed (N bytes received so far) [receiver]"
at near-identical byte cutoffs (615163, 2251130, 2251135, 2251388).
Wire-byte capture against the upstream rsync 3.4.3 client shows the
daemon-as-sender sends its final NDX_DONE + stats correctly, then
calls shutdown(SHUT_WR) immediately. The receiver sees FIN before it
has had a chance to write its trailing MSG_STATS + final NDX_DONE
through the generator-to-sender pipe, abandons the write, and reports
"connection unexpectedly closed".

Upstream avoids this race via its fork model: the sender child holds
the only fd reference, and FIN is only queued once the kernel reaps
the exited process - long after the receiver has flushed its goodbye.
Our threaded daemon has multiple cloned TcpStream handles for the
same socket and was forcing FIN via an explicit shutdown(SHUT_WR)
between the engine's last write and the receiver's still-in-flight
goodbye writes.

Drop the half-close. Keep SO_LINGER(5s) so the daemon's TX bytes
reach the peer before close() returns. Replace the 2s drain with a
read-until-EOF loop bounded at 5s, mirroring upstream's
noop_io_until_death() pattern: keep reading from the peer until it
finishes its own goodbye and FINs (its own exit_cleanup), then close.

Verified locally on a Linux/aarch64 host against the upstream rsync
3.4.3 testsuite daemon-gzip-download scenario.
…sion

Locks in the fix from the prior commit by exercising the daemon-as-sender
+ -z pull pattern that triggers cluster A. Pulls a 3-file tree (28 B,
52 KB, 1 MB) through run_client with compression enabled; a regressed
goodbye drain surfaces as 'connection unexpectedly closed (N bytes
received so far)' inside run_client and fails the assertion.
@oferchen
oferchen force-pushed the fix/uts-v3-a-shutdown-race branch from d50486d to 12abf0d Compare June 14, 2026 08:22
@oferchen
oferchen merged commit cbb4128 into master Jun 14, 2026
9 of 10 checks passed
@oferchen
oferchen deleted the fix/uts-v3-a-shutdown-race branch June 14, 2026 11:57
oferchen added a commit that referenced this pull request Aug 24, 2026
…cluster A (#5765)

* fix(daemon): drain peer goodbye without half-close to unblock UTS-v3 cluster A

UTS-v3 Cluster A: 4 upstream testsuite failures (batch-mode, alt-dest,
daemon-gzip-download, daemon-refuse-compress) all surface as
"connection unexpectedly closed (N bytes received so far) [receiver]"
at near-identical byte cutoffs (615163, 2251130, 2251135, 2251388).
Wire-byte capture against the upstream rsync 3.4.3 client shows the
daemon-as-sender sends its final NDX_DONE + stats correctly, then
calls shutdown(SHUT_WR) immediately. The receiver sees FIN before it
has had a chance to write its trailing MSG_STATS + final NDX_DONE
through the generator-to-sender pipe, abandons the write, and reports
"connection unexpectedly closed".

Upstream avoids this race via its fork model: the sender child holds
the only fd reference, and FIN is only queued once the kernel reaps
the exited process - long after the receiver has flushed its goodbye.
Our threaded daemon has multiple cloned TcpStream handles for the
same socket and was forcing FIN via an explicit shutdown(SHUT_WR)
between the engine's last write and the receiver's still-in-flight
goodbye writes.

Drop the half-close. Keep SO_LINGER(5s) so the daemon's TX bytes
reach the peer before close() returns. Replace the 2s drain with a
read-until-EOF loop bounded at 5s, mirroring upstream's
noop_io_until_death() pattern: keep reading from the peer until it
finishes its own goodbye and FINs (its own exit_cleanup), then close.

Verified locally on a Linux/aarch64 host against the upstream rsync
3.4.3 testsuite daemon-gzip-download scenario.

* test(daemon): add UTS-v3 cluster A compress-pull goodbye-drain regression

Locks in the fix from the prior commit by exercising the daemon-as-sender
+ -z pull pattern that triggers cluster A. Pulls a 3-file tree (28 B,
52 KB, 1 MB) through run_client with compression enabled; a regressed
goodbye drain surfaces as 'connection unexpectedly closed (N bytes
received so far)' inside run_client and fails the assertion.
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