Skip to content

fix(transfer): drive pipe stdout to EOF in receiver close path to break SSH/local-rsh deadlock - #5786

Merged
oferchen merged 1 commit into
masterfrom
fix/master-receiver-drain-bounded-timeout
Jun 14, 2026
Merged

oferchen merged 1 commit into
masterfrom
fix/master-receiver-drain-bounded-timeout

Conversation

@oferchen

@oferchen oferchen commented Jun 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

Fixes a pre-existing master CI regression in the interop / interop with upstream rsync job. On master HEAD the standalone phase reports Standalone: 69/72 passed, 1 known, 2 unexpected because two interop tests deadlock and get terminated 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)

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 --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 proceeds to exit_cleanup. That works for the SSH SOCK_STREAM transport but is a no-op on the --rsh=<wrapper> 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.

Fix

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.

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

  • Updated the pipe regression test (shutdown_stdio_write_drives_pipe_peer_to_eof, formerly shutdown_stdio_write_surfaces_enotsock_on_pipe) to assert EOF observability via the new fallback path.
  • Added close_write_side_pipe_returns_ok exercising the fallback directly on a pipe FD without redirecting STDOUT_FILENO, so it runs safely under parallel test threads.
  • The existing SSH socket-pair tests (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

Test plan

upstream: io.c:943-963 noop_io_until_death() (read loop that terminates on 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
oferchen force-pushed the fix/master-receiver-drain-bounded-timeout branch from 5056bcc to 3f101f2 Compare June 14, 2026 16:48
@github-actions github-actions Bot added the bug Something isn't working label Jun 14, 2026
@oferchen
oferchen force-pushed the fix/master-receiver-drain-bounded-timeout branch from 3f101f2 to edcf57d Compare June 14, 2026 16:51
@oferchen oferchen changed the title fix(transfer): bound receiver post-goodbye stdin drain to avoid SSH/local-rsh deadlock fix(transfer): drive pipe stdout to EOF in receiver close path to break SSH/local-rsh deadlock Jun 14, 2026
@oferchen
oferchen force-pushed the fix/master-receiver-drain-bounded-timeout branch 3 times, most recently from ba4e20f to 1bb728f Compare June 14, 2026 18:24
…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
oferchen force-pushed the fix/master-receiver-drain-bounded-timeout branch from 1bb728f to db73670 Compare June 14, 2026 19:19
@oferchen
oferchen merged commit acda6a5 into master Jun 14, 2026
61 of 69 checks passed
@oferchen
oferchen deleted the fix/master-receiver-drain-bounded-timeout branch June 14, 2026 20:33
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).
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