Skip to content

fix(transfer): drain stdin to EOF in SSH receiver after goodbye - #5771

Merged
oferchen merged 1 commit into
masterfrom
fix/uts-v3-a-ssh-goodbye
Jun 14, 2026
Merged

oferchen merged 1 commit into
masterfrom
fix/uts-v3-a-ssh-goodbye

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • UTS-v3 Cluster A (SSH leg): alt-dest reaches oc-rsync through lsh.sh --rsync-path=oc-rsync (SSH transport), not through the daemon. PR fix(daemon): drain peer goodbye without half-close to unblock UTS-v3 cluster A #5765 fixed the daemon-as-sender leg with SO_LINGER + TCP drain in process_approved_module, but the SSH receiver path was untouched and continued to fail with connection unexpectedly closed (2251388 bytes received so far) [receiver] at the same wire-byte signature as the daemon cluster.
  • Root cause: after finalize_transfer writes its final NDX_DONE the --server --receiver process returns from run_server_stdio and exits immediately, dropping the SSH stdio pipe end. The upstream sender, still in read_final_goodbye(), sees EOF on the bytes it is still streaming and reports the cluster A diagnostic.
  • Fix: drain stdin to EOF at the CLI --server boundary for the receiver role. Mirrors upstream's receiver child which loops on read_buf(iobuf.in_fd, ...) via noop_io_until_death() (io.c:943) until its parent reaps it. The peer FINs as part of its own exit_cleanup, our read returns 0, and we unblock cleanly.

Scope

Upstream reference

  • io.c:943-963 noop_io_until_death() - receiver-side keep-reading loop.
  • main.c:1075 receiver-child loop on read_final_goodbye().
  • cleanup.c:254 noop_io_until_death() call inside _exit_cleanup.

Test plan

  • CI: fmt + clippy, nextest (stable), Windows, macOS, Linux musl.
  • Linux interop: rerun runtests.py alt-dest against upstream 3.4.3 and confirm the SSH-mode invocation completes without connection unexpectedly closed.
  • Verify daemon UTS-v3 cluster A regression test (daemon_compress_pull_drains_peer_goodbye_for_uts_v3_cluster_a) still passes - the fix is additive and runs only on the SSH path.

@github-actions github-actions Bot added the bug Something isn't working label Jun 14, 2026
@oferchen
oferchen force-pushed the fix/uts-v3-a-ssh-goodbye branch 2 times, most recently from f1acc6b to 8b17759 Compare June 14, 2026 10:31
UTS-v3 Cluster A surfaced four upstream testsuite failures
(`batch-mode`, `alt-dest`, `daemon-gzip-download`, `daemon-refuse-compress`)
all reporting "connection unexpectedly closed (N bytes received so far)
[receiver]" at near-identical byte cutoffs. PR 5765 fixed the
daemon-as-sender leg by dropping the half-close and adding SO_LINGER plus
a TCP drain, but `alt-dest` reaches oc-rsync through the SSH transport
(lsh.sh wrapping `--rsync-path=oc-rsync`), which does not flow through
`daemon::sections::module_access::transfer`. The race re-surfaced on the
SSH path: the upstream sender keeps writing trailing MSG_STATS / NDX_DONE
bytes after our final NDX_DONE, but the `--server --receiver` process
returns from `run_server_stdio` and exits immediately, closing the SSH
stdio pipes. The upstream sender then sees EOF in `read_final_goodbye()`
before the bytes it is still streaming reach us, and reports
"connection unexpectedly closed".

Upstream's receiver child mirrors this with `noop_io_until_death()` in
io.c:943 - after writing its final goodbye it loops on
`read_buf(iobuf.in_fd, ...)` until the parent reaps it. The threaded
oc-rsync collapses receiver and generator into one process, so drain
stdin to EOF in the CLI `--server` boundary instead. The upstream peer
FINs its end of the pipe as part of its own `exit_cleanup`, our read
returns 0, and we unblock.

Gated to the receiver role: the generator (sender) side does not face
this race because its peer closes its read end first. Daemon mode is
unaffected because the daemon dispatches into `run_server_with_handshake`
directly and runs its own TCP drain in `process_approved_module`.

upstream: io.c:943-963 noop_io_until_death(), main.c:1075 receiver-child
loop on read_final_goodbye(), cleanup.c:254 noop_io_until_death() call
in _exit_cleanup.
@oferchen
oferchen force-pushed the fix/uts-v3-a-ssh-goodbye branch from 8b17759 to 560af54 Compare June 14, 2026 11:18
@oferchen
oferchen merged commit e9725ed into master Jun 14, 2026
42 of 67 checks passed
@oferchen
oferchen deleted the fix/uts-v3-a-ssh-goodbye branch June 14, 2026 11:57
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 Aug 24, 2026
UTS-v3 Cluster A surfaced four upstream testsuite failures
(`batch-mode`, `alt-dest`, `daemon-gzip-download`, `daemon-refuse-compress`)
all reporting "connection unexpectedly closed (N bytes received so far)
[receiver]" at near-identical byte cutoffs. PR 5765 fixed the
daemon-as-sender leg by dropping the half-close and adding SO_LINGER plus
a TCP drain, but `alt-dest` reaches oc-rsync through the SSH transport
(lsh.sh wrapping `--rsync-path=oc-rsync`), which does not flow through
`daemon::sections::module_access::transfer`. The race re-surfaced on the
SSH path: the upstream sender keeps writing trailing MSG_STATS / NDX_DONE
bytes after our final NDX_DONE, but the `--server --receiver` process
returns from `run_server_stdio` and exits immediately, closing the SSH
stdio pipes. The upstream sender then sees EOF in `read_final_goodbye()`
before the bytes it is still streaming reach us, and reports
"connection unexpectedly closed".

Upstream's receiver child mirrors this with `noop_io_until_death()` in
io.c:943 - after writing its final goodbye it loops on
`read_buf(iobuf.in_fd, ...)` until the parent reaps it. The threaded
oc-rsync collapses receiver and generator into one process, so drain
stdin to EOF in the CLI `--server` boundary instead. The upstream peer
FINs its end of the pipe as part of its own `exit_cleanup`, our read
returns 0, and we unblock.

Gated to the receiver role: the generator (sender) side does not face
this race because its peer closes its read end first. Daemon mode is
unaffected because the daemon dispatches into `run_server_with_handshake`
directly and runs its own TCP drain in `process_approved_module`.

upstream: io.c:943-963 noop_io_until_death(), main.c:1075 receiver-child
loop on read_final_goodbye(), cleanup.c:254 noop_io_until_death() call
in _exit_cleanup.
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