Repository navigation
fix(transfer): half-close stdout after receiver goodbye to break SSH/lsh.sh shutdown deadlock - #5781
Merged
Merged
Conversation
…down deadlock
The `--server` receiver under SSH/lsh.sh transports completed its
NDX_DONE handshake then entered a drain-stdin loop, but never closed
its own write side. The upstream sender, meanwhile, was in
`noop_io_until_death()` reading-until-EOF on the receiver's stdout.
Both sides waited for the other to close their write end; neither
did. Kernel stacks under gdb confirmed the deadlock:
- sender: hrtimer_nanosleep (msleep loop in noop_io_until_death)
- receiver: unix_stream_data_wait inside read(STDIN_FILENO)
The fix issues `shutdown(STDOUT_FILENO, SHUT_WR)` after flushing the
final goodbye envelope. On the SSH / lsh.sh transport stdout is a
stream socket, so the half-close sends FIN to the peer and unblocks
its `read_final_goodbye`. The peer then exits, closes its own write
side, and the receiver's drain loop sees EOF deterministically.
A new `fast_io::shutdown_stdio_write()` helper wraps the syscall under
SAFETY-commented unsafe (consolidating unsafe into the permitted
crate). On non-socket stdout the syscall returns ENOTSOCK; the caller
treats it as best-effort. Windows builds are a no-op since the
inherited stdio handles are not sockets there.
upstream: io.c:943-963 `noop_io_until_death()`,
cleanup.c:254 call in `_exit_cleanup`
oferchen
force-pushed
the
fix/uts-v3-half-close-server-drain
branch
from
June 14, 2026 16:25
9a69e95 to
960a97c
Compare
oferchen
added a commit
that referenced
this pull request
Jun 14, 2026
…ocal-rsh deadlock The unbounded EOF drain added in PR #5771 to the receiver-role server exit path deadlocks on the SSH / `--rsh=fake_rsh --rsync-path=oc-rsync` transport used by the standalone interop harness. The upstream sender's `read_final_goodbye()` keeps the connection open until our stdout BufWriter is flushed and closed by process exit; the drain blocks on its EOF, and process exit cannot run until the drain returns. Each side waits on the other. This was visible on master HEAD as two `interop / interop with upstream rsync` standalone failures, both 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) Bound the drain to 250 ms via a background worker plus `recv_timeout`. Upstream's `noop_io_until_death()` (io.c:943-963) arms a 60 s `io_timeout` before its own read loop and treats EOF inside that window as a clean exit (`kluge_around_eof = 2` -> `exit_cleanup(0)` at io.c:217-232) - the same behaviour we now adopt with a tighter bound. 250 ms is comfortably above loopback round-trip and well below the 10 s upstream `--timeout` configured by the interop harness. The wire-protocol goodbye envelope itself is unchanged: only the post-envelope no-op drain becomes bounded. The cluster A regression PR #5771 was added to fix is still covered: the peer's trailing bytes arrive within microseconds of the goodbye and complete the drain naturally before the 250 ms ceiling. PR #5780 closed a 200 ms-bound proposal in favour of the deterministic half-close approach in PR #5781, but CI run 27503163030 confirmed the half-close alone still hits the same two timeouts. A bounded drain is required because the peer waits for our stdout FIN, which only fires on process exit. upstream: io.c:943-963 `noop_io_until_death()`; io.c:217-232 `whine_about_eof()` clean exit when `kluge_around_eof > 0`; cleanup.c:254 `noop_io_until_death()` call in `_exit_cleanup`.
oferchen
added a commit
that referenced
this pull request
Jun 14, 2026
…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
added a commit
that referenced
this pull request
Jun 14, 2026
…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
added a commit
that referenced
this pull request
Jun 14, 2026
…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
added a commit
that referenced
this pull request
Jun 14, 2026
…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
added a commit
that referenced
this pull request
Jun 14, 2026
…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
added a commit
that referenced
this pull request
Jun 14, 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
…down deadlock (#5781) The `--server` receiver under SSH/lsh.sh transports completed its NDX_DONE handshake then entered a drain-stdin loop, but never closed its own write side. The upstream sender, meanwhile, was in `noop_io_until_death()` reading-until-EOF on the receiver's stdout. Both sides waited for the other to close their write end; neither did. Kernel stacks under gdb confirmed the deadlock: - sender: hrtimer_nanosleep (msleep loop in noop_io_until_death) - receiver: unix_stream_data_wait inside read(STDIN_FILENO) The fix issues `shutdown(STDOUT_FILENO, SHUT_WR)` after flushing the final goodbye envelope. On the SSH / lsh.sh transport stdout is a stream socket, so the half-close sends FIN to the peer and unblocks its `read_final_goodbye`. The peer then exits, closes its own write side, and the receiver's drain loop sees EOF deterministically. A new `fast_io::shutdown_stdio_write()` helper wraps the syscall under SAFETY-commented unsafe (consolidating unsafe into the permitted crate). On non-socket stdout the syscall returns ENOTSOCK; the caller treats it as best-effort. Windows builds are a no-op since the inherited stdio handles are not sockets there. upstream: io.c:943-963 `noop_io_until_death()`, cleanup.c:254 call in `_exit_cleanup`
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`.
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
The
--serverreceiver under SSH/lsh.sh transports completes its NDX_DONE handshake then enters a drain-stdin loop, but never closes its own write side. The upstream sender, meanwhile, is innoop_io_until_death()reading-until-EOF on the receiver's stdout. Both sides wait for the other to close their write end; neither does.This is the root cause of cluster-A upstream-testsuite hangs (00-hello, alt-dest, files-from, ssh-basic, symlink-dirlink-basis, hardlinks): the transfer completes, both sides emit goodbye, then 300s timeout.
Root-cause evidence
Reproduced on Linux host, captured kernel stacks of the deadlock:
Upstream sender (rsync 3.4.3, the SSH/lsh.sh client):
This is
msleep(20)inside upstream'snoop_io_until_death()poll loop (io.c:943-963).oc-rsync receiver (
--serverunder lsh.sh):Blocked in
read(fd=0)on the inherited stdin Unix socket.Socket queues: both Send-Q and Recv-Q = 0; no bytes in flight.
Both sides are reading-until-EOF on each other; neither closes its write side first.
The fix
After flushing the final goodbye envelope in the receiver-role
--serverexit path, issueshutdown(STDOUT_FILENO, SHUT_WR). On the SSH / lsh.sh transport stdout is a stream socket, so the half-close sends FIN to the peer. The peer'sread_final_goodbye()then sees EOF, completesexit_cleanup, and closes its own write side. Our drain loop then sees EOF deterministically.A new
fast_io::shutdown_stdio_write()helper wraps the unsafe syscall under SAFETY comments, keeping unsafe code consolidated infast_io(per the unsafe-code policy).On non-socket stdout (regular pipe) the syscall returns ENOTSOCK; the caller treats it as best-effort. Windows builds are a no-op since the inherited stdio handles are not sockets there.
Upstream reference
target/interop/upstream-src/rsync-3.4.1/io.c:943-963noop_io_until_death()target/interop/upstream-src/rsync-3.4.1/cleanup.c:254call in_exit_cleanupTest plan
00-helloupstream test (was hanging, should pass)alt-destupstream test (was hanging, should pass)files-fromupstream test (was hanging, should pass)ssh-basicupstream test (was hanging, should pass)symlink-dirlink-basisupstream test (was hanging, should pass)hardlinksupstream test (was hanging, should pass)stdio_shutdown.rsexercise FIN propagation on a socket pair, ENOTSOCK on a pipe, and BufWriter flush + half-close ordering)--serverreceiver under SSH/lsh.sh)