Repository navigation
fix(transfer): drive pipe stdout to EOF in receiver close path to break SSH/local-rsh deadlock - #5786
Merged
Conversation
oferchen
force-pushed
the
fix/master-receiver-drain-bounded-timeout
branch
from
June 14, 2026 16:48
5056bcc to
3f101f2
Compare
oferchen
force-pushed
the
fix/master-receiver-drain-bounded-timeout
branch
from
June 14, 2026 16:51
3f101f2 to
edcf57d
Compare
oferchen
force-pushed
the
fix/master-receiver-drain-bounded-timeout
branch
3 times, most recently
from
June 14, 2026 18:24
ba4e20f to
1bb728f
Compare
…ak SSH/local-rsh deadlock PR #5781 made the receiver-role `--server` exit path call `shutdown(STDOUT_FILENO, SHUT_WR)` after the goodbye flush so the upstream peer's `read_final_goodbye()` (io.c:943-963) sees EOF and its `exit_cleanup` runs. That works for the SSH `SOCK_STREAM` transport but is a no-op on the `--rsh=fake_rsh --rsync-path=oc-rsync` interop transport: upstream rsync's remote-shell launcher uses `popen2`-style pipes, not socketpairs, so `shutdown(SHUT_WR)` returns ENOTSOCK and the receiver's drain-stdin loop deadlocks waiting on a peer FIN that never arrives. Two standalone interop tests on master HEAD hit this deadlock and get killed by the harness `timeout 30s`: - test_iconv_local_ssh_interop direction-b (tools/ci/run_interop.sh:3530) - test_compress_ssh_interop direction-b (tools/ci/run_interop.sh:3682) `interop / interop with upstream rsync` reports "Standalone: 69/72 passed, 1 known, 2 unexpected". Extend `fast_io::shutdown_stdio_write` to fall back to `dup2(/dev/null, STDOUT_FILENO)` when `shutdown(SHUT_WR)` returns ENOTSOCK. The dup2 atomically closes the original pipe write end (the peer's read returns 0 deterministically) while keeping FD 1 a valid writable sink so any late stray write to stdout does not error with EBADF. The SSH `SOCK_STREAM` half-close path is unchanged; only the pipe fallback is new. Update the pipe regression test to assert EOF observability via the new fallback path, and add a direct test of `close_write_side` on a pipe FD without touching STDOUT_FILENO so it runs safely under parallel test threads. The wire-protocol goodbye envelope itself is unchanged: `flush()` still pushes the buffered NDX_DONE down before the close, and the peer observes the same bytes followed by EOF on both transports. upstream: io.c:943-963 `noop_io_until_death()` reads until EOF; io.c:217-232 `whine_about_eof()` treats EOF inside the `kluge_around_eof` window as a clean exit; cleanup.c:254 `noop_io_until_death()` call in `_exit_cleanup`.
oferchen
force-pushed
the
fix/master-receiver-drain-bounded-timeout
branch
from
June 14, 2026 19:19
1bb728f to
db73670
Compare
oferchen
added a commit
that referenced
this pull request
Jun 14, 2026
The two production sites that build `OutFormatContext` in `crates/cli/src/frontend/execution/drive/summary.rs` both used `OutFormatContext::default()` which left `is_sender` at `false`. This flipped the itemize direction arrow for SSH-push sender runs: oc-rsync emitted `>f+++++++++` where upstream rsync emits `<f+++++++++` because the formatter's polarity is already correct (`< if is_sender else >`) but the role was never threaded in. Empirical evidence from an SSH sweep against the PR #5786 binary showed 9 of 9 SSH-push scenarios emitted the wrong arrow. The destination tree was byte-identical with upstream; only the log line differed. upstream: log.c:701-704 c[0] = iflags & ITEM_LOCAL_CHANGE ? iflags & ITEM_XNAME_FOLLOWS ? 'h' : 'c' : !(iflags & ITEM_TRANSFER) ? '.' : !local_server && *op == 's' ? '<' : '>'; i.e. SSH-sender emits '<', everything else emits '>'. Fix: - Add `ClientConfig::is_local_sender()` which inspects `transfer_args` via the existing `client::remote::operand_is_remote` classifier. Push (remote dest, all-local sources) -> sender. Pull (any remote source) -> receiver. Local copy and empty-args -> sender (harmless because upstream hits the `local_server` branch which emits `>`). - Capture the flag before `config` is consumed by `run_client_with_observer` in `execute_transfer`. - Thread it into `OutFormatContext` via a new `with_is_sender` constructor, including the log-file path through a new `EmitLogOutputParams::is_sender` field. Wire protocol unaffected (purely user-facing log layer).
oferchen
added a commit
that referenced
this pull request
Jun 14, 2026
The two production sites that build `OutFormatContext` in `crates/cli/src/frontend/execution/drive/summary.rs` both used `OutFormatContext::default()` which left `is_sender` at `false`. This flipped the itemize direction arrow for SSH-push sender runs: oc-rsync emitted `>f+++++++++` where upstream rsync emits `<f+++++++++` because the formatter's polarity is already correct (`< if is_sender else >`) but the role was never threaded in. Empirical evidence from an SSH sweep against the PR #5786 binary showed 9 of 9 SSH-push scenarios emitted the wrong arrow. The destination tree was byte-identical with upstream; only the log line differed. upstream: log.c:701-704 c[0] = iflags & ITEM_LOCAL_CHANGE ? iflags & ITEM_XNAME_FOLLOWS ? 'h' : 'c' : !(iflags & ITEM_TRANSFER) ? '.' : !local_server && *op == 's' ? '<' : '>'; i.e. SSH-sender emits '<', everything else emits '>'. Fix: - Add `ClientConfig::is_local_sender()` which inspects `transfer_args` via the existing `client::remote::operand_is_remote` classifier. Push (remote dest, all-local sources) -> sender. Pull (any remote source) -> receiver. Local copy and empty-args -> sender (harmless because upstream hits the `local_server` branch which emits `>`). - Capture the flag before `config` is consumed by `run_client_with_observer` in `execute_transfer`. - Thread it into `OutFormatContext` via a new `with_is_sender` constructor, including the log-file path through a new `EmitLogOutputParams::is_sender` field. Wire protocol unaffected (purely user-facing log layer).
oferchen
added a commit
that referenced
this pull request
Jun 14, 2026
The two production sites that build `OutFormatContext` in `crates/cli/src/frontend/execution/drive/summary.rs` both used `OutFormatContext::default()` which left `is_sender` at `false`. This flipped the itemize direction arrow for SSH-push sender runs: oc-rsync emitted `>f+++++++++` where upstream rsync emits `<f+++++++++` because the formatter's polarity is already correct (`< if is_sender else >`) but the role was never threaded in. Empirical evidence from an SSH sweep against the PR #5786 binary showed 9 of 9 SSH-push scenarios emitted the wrong arrow. The destination tree was byte-identical with upstream; only the log line differed. upstream: log.c:701-704 c[0] = iflags & ITEM_LOCAL_CHANGE ? iflags & ITEM_XNAME_FOLLOWS ? 'h' : 'c' : !(iflags & ITEM_TRANSFER) ? '.' : !local_server && *op == 's' ? '<' : '>'; i.e. SSH-sender emits '<', everything else emits '>'. Fix: - Add `ClientConfig::is_local_sender()` which inspects `transfer_args` via the existing `client::remote::operand_is_remote` classifier. Push (remote dest, all-local sources) -> sender. Pull (any remote source) -> receiver. Local copy and empty-args -> sender (harmless because upstream hits the `local_server` branch which emits `>`). - Capture the flag before `config` is consumed by `run_client_with_observer` in `execute_transfer`. - Thread it into `OutFormatContext` via a new `with_is_sender` constructor, including the log-file path through a new `EmitLogOutputParams::is_sender` field. Wire protocol unaffected (purely user-facing log layer).
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
…ak SSH/local-rsh deadlock (#5786) PR #5781 made the receiver-role `--server` exit path call `shutdown(STDOUT_FILENO, SHUT_WR)` after the goodbye flush so the upstream peer's `read_final_goodbye()` (io.c:943-963) sees EOF and its `exit_cleanup` runs. That works for the SSH `SOCK_STREAM` transport but is a no-op on the `--rsh=fake_rsh --rsync-path=oc-rsync` interop transport: upstream rsync's remote-shell launcher uses `popen2`-style pipes, not socketpairs, so `shutdown(SHUT_WR)` returns ENOTSOCK and the receiver's drain-stdin loop deadlocks waiting on a peer FIN that never arrives. Two standalone interop tests on master HEAD hit this deadlock and get killed by the harness `timeout 30s`: - test_iconv_local_ssh_interop direction-b (tools/ci/run_interop.sh:3530) - test_compress_ssh_interop direction-b (tools/ci/run_interop.sh:3682) `interop / interop with upstream rsync` reports "Standalone: 69/72 passed, 1 known, 2 unexpected". Extend `fast_io::shutdown_stdio_write` to fall back to `dup2(/dev/null, STDOUT_FILENO)` when `shutdown(SHUT_WR)` returns ENOTSOCK. The dup2 atomically closes the original pipe write end (the peer's read returns 0 deterministically) while keeping FD 1 a valid writable sink so any late stray write to stdout does not error with EBADF. The SSH `SOCK_STREAM` half-close path is unchanged; only the pipe fallback is new. Update the pipe regression test to assert EOF observability via the new fallback path, and add a direct test of `close_write_side` on a pipe FD without touching STDOUT_FILENO so it runs safely under parallel test threads. The wire-protocol goodbye envelope itself is unchanged: `flush()` still pushes the buffered NDX_DONE down before the close, and the peer observes the same bytes followed by EOF on both transports. upstream: io.c:943-963 `noop_io_until_death()` reads until EOF; io.c:217-232 `whine_about_eof()` treats EOF inside the `kluge_around_eof` window as a clean exit; cleanup.c:254 `noop_io_until_death()` call in `_exit_cleanup`.
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
The two production sites that build `OutFormatContext` in `crates/cli/src/frontend/execution/drive/summary.rs` both used `OutFormatContext::default()` which left `is_sender` at `false`. This flipped the itemize direction arrow for SSH-push sender runs: oc-rsync emitted `>f+++++++++` where upstream rsync emits `<f+++++++++` because the formatter's polarity is already correct (`< if is_sender else >`) but the role was never threaded in. Empirical evidence from an SSH sweep against the PR #5786 binary showed 9 of 9 SSH-push scenarios emitted the wrong arrow. The destination tree was byte-identical with upstream; only the log line differed. upstream: log.c:701-704 c[0] = iflags & ITEM_LOCAL_CHANGE ? iflags & ITEM_XNAME_FOLLOWS ? 'h' : 'c' : !(iflags & ITEM_TRANSFER) ? '.' : !local_server && *op == 's' ? '<' : '>'; i.e. SSH-sender emits '<', everything else emits '>'. Fix: - Add `ClientConfig::is_local_sender()` which inspects `transfer_args` via the existing `client::remote::operand_is_remote` classifier. Push (remote dest, all-local sources) -> sender. Pull (any remote source) -> receiver. Local copy and empty-args -> sender (harmless because upstream hits the `local_server` branch which emits `>`). - Capture the flag before `config` is consumed by `run_client_with_observer` in `execute_transfer`. - Thread it into `OutFormatContext` via a new `with_is_sender` constructor, including the log-file path through a new `EmitLogOutputParams::is_sender` field. Wire protocol unaffected (purely user-facing log layer).
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
Fixes a pre-existing master CI regression in the
interop / interop with upstream rsyncjob. On master HEAD the standalone phase reportsStandalone: 69/72 passed, 1 known, 2 unexpectedbecause two interop tests deadlock and get terminated by the harnesstimeout 30s:test_iconv_local_ssh_interopdirection-b (tools/ci/run_interop.sh:3530)test_compress_ssh_interopdirection-b (tools/ci/run_interop.sh:3682)Both upstream rsync invocations use
--rsh=fake_rsh --rsync-path=oc-rsync, making oc-rsync the spawned--server --receiver.Root cause
PR #5781 made the receiver-role
--serverexit path callshutdown(STDOUT_FILENO, SHUT_WR)after the goodbye flush so the upstream peer'sread_final_goodbye()(io.c:943-963) sees EOF and proceeds toexit_cleanup. That works for the SSHSOCK_STREAMtransport but is a no-op on the--rsh=<wrapper>interop transport: upstream rsync's remote-shell launcher usespopen2-style pipes, not socketpairs, soshutdown(SHUT_WR)returnsENOTSOCKand the receiver's drain-stdin loop deadlocks waiting on a peer FIN that never arrives.Fix
Extend
fast_io::shutdown_stdio_writeto fall back todup2(/dev/null, STDOUT_FILENO)whenshutdown(SHUT_WR)returnsENOTSOCK. Thedup2atomically closes the original pipe write end (the peer's read returns 0 deterministically) while keeping FD 1 a valid writable sink so any late stray write to stdout does not error withEBADF. The SSHSOCK_STREAMhalf-close path is unchanged; only the pipe fallback is new.The wire-protocol goodbye envelope itself still goes out exactly as before through
run_server_stdio:flush()pushes the buffered NDX_DONE down to the kernel before the close, and the peer observes the same bytes followed by EOF on both transports. No timer is introduced; EOF is signalled by the close primitive itself.Tests
shutdown_stdio_write_drives_pipe_peer_to_eof, formerlyshutdown_stdio_write_surfaces_enotsock_on_pipe) to assert EOF observability via the new fallback path.close_write_side_pipe_returns_okexercising the fallback directly on a pipe FD without redirectingSTDOUT_FILENO, so it runs safely under parallel test threads.shutdown_stdio_write_sends_fin_on_socket,shutdown_stdio_write_is_observable_to_buffered_writer) cover the unchanged half-close path and are preserved.Prior art
shutdown_stdio_write()and wired it into the receiver exit path; it fixed the socket transports but the pipe transports still hang. This PR extends that helper rather than duplicating it.Test plan
interop / interop with upstream rsyncstandalone reports 72/72 passing (or matches the known-failure baseline)shutdown_stdio_write_sends_fin_on_socket/shutdown_stdio_write_is_observable_to_buffered_writersocket testsupstream:
io.c:943-963noop_io_until_death()(read loop that terminates on EOF);io.c:217-232whine_about_eof()treats EOF inside thekluge_around_eofwindow as a clean exit;cleanup.c:254noop_io_until_death()call in_exit_cleanup.