Skip to content

fix(transfer): bound SSH receiver drain to 200ms after flushing stdout - #5780

Closed
oferchen wants to merge 1 commit into
masterfrom
fix/uts-v3-bounded-server-drain
Closed

oferchen wants to merge 1 commit into
masterfrom
fix/uts-v3-bounded-server-drain

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

PR #5771 added an unbounded stdin-drain loop on the SSH receiver exit path. Five upstream-testsuite tests under the lsh.sh transport - alt-dest, 00-hello, ssh-basic, symlink-dirlink-basis, and hardlinks - now hit a deadlock between the drain and the upstream sender's read_final_goodbye(), surfacing as 300-600s runner timeouts.

strace on the hung oc-rsync confirms unix_stream_data_wait on stdin fd 0, with the upstream client blocked in wait4. The receiver's own NDX_DONE is still sitting in the outer stdout BufWriter when the drain starts, so the peer's read_final_goodbye never completes and its exit_cleanup never closes its write end.

Two minimal changes break the deadlock without losing the original cluster A protection:

  • Flush stdout before draining so the peer sees our final goodbye and proceeds with exit_cleanup.
  • Cap the drain at 200ms - well above the loopback round-trip, well below any runner per-test timeout. Sender's exit_cleanup completes within microseconds of receiving our flushed NDX_DONE.

upstream: io.c:943-963 noop_io_until_death(); cleanup.c:254 noop_io_until_death() call in _exit_cleanup.

Test plan

The drain loop added in PR #5771 reads stdin to EOF on every receiver-role
SSH server exit. The upstream sender's exit_cleanup closes its write end
only after `read_final_goodbye()` has seen our NDX_DONE; if our NDX_DONE
is still buffered in the outer `stdout` BufWriter when the drain starts,
neither side ever closes its write end and both block in `read()`.

Five tests under upstream-testsuite's lsh.sh transport hit this deadlock:
alt-dest, 00-hello, ssh-basic, symlink-dirlink-basis, hardlinks. strace on
the hung oc-rsync server confirms `unix_stream_data_wait` on the stdin
socket fd, with the upstream client process blocked in `wait4`.

Fix the deadlock with two minimal changes:

  * Flush `stdout` before draining so the peer's `read_final_goodbye`
    completes and its `exit_cleanup` can proceed.
  * Cap the drain wall-clock at 200ms. Sender's exit_cleanup completes
    within microseconds of receiving our flushed goodbye; 200ms is well
    above the loopback round trip and well below any runner timeout. If
    the peer fails to FIN within that window, exit anyway rather than
    hanging the test runner.

upstream: io.c:943-963 noop_io_until_death(); cleanup.c:254
noop_io_until_death() call in _exit_cleanup.
@github-actions github-actions Bot added the bug Something isn't working label Jun 14, 2026
@oferchen

Copy link
Copy Markdown
Owner Author

Closing in favor of the deterministic fix. The half-close (shutdown(SHUT_WR)) avoids the timer-based band-aid by signaling EOF to the peer's read_final_goodbye() directly. Re-opening in a fresh PR.

@oferchen oferchen closed this Jun 14, 2026
@oferchen
oferchen deleted the fix/uts-v3-bounded-server-drain branch June 14, 2026 12: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`.
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