Repository navigation
fix(daemon): drain peer goodbye without half-close to unblock UTS-v3 cluster A - #5765
Merged
Merged
Conversation
…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
force-pushed
the
fix/uts-v3-a-shutdown-race
branch
from
June 14, 2026 08:22
d50486d to
12abf0d
Compare
3 tasks
This was referenced Jun 14, 2026
fix(transfer): drive pipe stdout to EOF in receiver close path to break SSH/local-rsh deadlock
#5786
Merged
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.
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
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 trailingMSG_STATS+NDX_DONEthrough the receiver-to-generator pipe. The receiver saw FIN, abandoned its writes, and emittedconnection 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 beforeclose()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 withoutSHUTDOWN_ALL_SOCKETS; the kernel handles cleanup once the sender child exits) and thenoop_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 locallycargo 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 locallydaemon-gzip-download,daemon-refuse-compress,batch-mode,alt-dest(verified on Linux/aarch64 against upstream rsync 3.4.3)