Skip to content

feat(rsync_io): async stderr drain task for SSH socketpair (#2373) - #4363

Merged
oferchen merged 1 commit into
masterfrom
feat/ssh-async-stderr-drain
May 18, 2026
Merged

oferchen merged 1 commit into
masterfrom
feat/ssh-async-stderr-drain

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

SSE-4 (tracker #2373) from docs/design/socketpair-stderr-channel.md.

Adds an async stderr drain task that replaces Stdio::inherit() in
AsyncSshTransport when both async-ssh and the new
ssh-socketpair-stderr feature are enabled.

  • New async_stderr_drain module gated on both features. Spawns a tokio
    task that reads line-by-line from the parent end of the SSH stderr
    socketpair (installed by aux_channel::configure_stderr_channel),
    appends bytes into a bounded RingBuffer<8192>, and emits a
    tracing::warn!(target = "ssh::stderr", ...) per line.
  • AsyncSshTransport gains a private stderr_drain: Option<...> field
    and a public stderr_capture() -> Vec<u8> snapshot accessor. On
    configurations without the feature (or non-Unix), stderr_capture
    always returns an empty Vec so call sites stay unconditional.
  • Falls back to Stdio::inherit on socketpair FD exhaustion, as the
    design doc prescribes for the async path.

The sync transport's SocketpairStderrChannel thread drain is
unchanged. The new feature is opt-in and default off.

Test plan

  • cargo fmt --all clean
  • New unit tests cover (Unix-only):
    • 1 KiB payload round-trips through the drain and equals the snapshot
    • Multi-line input: each line lands in capture (warn-per-line path
      exercised; tracing dispatcher not asserted on to avoid global-state
      flakiness across tests)
    • Dropping the writer half terminates the drain task cleanly (join
      returns Ok)
    • Snapshot accessor is safe while the task is still live
    • Writing 2x cap caps the snapshot at ASYNC_STDERR_BUFFER_CAP
    • RingBuffer extend / oversized-extend / empty-extend semantics
  • CI: fmt+clippy, nextest (stable), Windows (stable), macOS (stable),
    Linux musl (stable)
  • Default-feature builds remain on the inherit path (verified by the
    #[cfg(not(...))] branch and the stderr_capture_is_empty_when_feature_disabled
    compile-only check)

@github-actions github-actions Bot added the enhancement New feature or request label May 17, 2026
oferchen added a commit that referenced this pull request May 18, 2026
SSE-6 from docs/design/socketpair-stderr-channel.md. Drives the SSE-3
`make_stderr_socketpair` primitive end-to-end by wiring the child end
into a real subprocess as fd 2 and asserting the parent end surfaces
the bytes verbatim. Each captured line additionally fires a
`tracing::warn!` event, mirroring the production drain shape staged
in SSE-4 (#4363) so this test continues to exercise the observable
contract once the async path lands.

Scenarios:
- single_error_line_propagates_through_socketpair: one echo writes
  `test error message\n`; parent buffer matches byte-for-byte and a
  single WARN event fires with the captured payload.
- multi_error_lines_propagate_and_fire_one_warn_each: three separate
  echo calls produce three ordered lines; all three are captured in
  order and one WARN event fires per line.
- drain_returns_after_child_exit_closes_child_end: confirms the drain
  observes EOF cleanly when the subprocess exits and the child end
  closes, guarding the failure mode the design doc calls out under
  "Tokio drain task survives past child reap".

Gated `cfg(all(unix, feature = "ssh-socketpair-stderr"))` so the file
no-ops on Windows and on default builds. Adds `tracing` and
`tracing-subscriber` as dev-dependencies of `rsync_io`; a custom
`Layer` records WARN events with thread-local dispatch propagated to
the spawned drain thread.
oferchen added a commit that referenced this pull request May 18, 2026
SSE-6 from docs/design/socketpair-stderr-channel.md. Drives the SSE-3
`make_stderr_socketpair` primitive end-to-end by wiring the child end
into a real subprocess as fd 2 and asserting the parent end surfaces
the bytes verbatim. Each captured line additionally fires a
`tracing::warn!` event, mirroring the production drain shape staged
in SSE-4 (#4363) so this test continues to exercise the observable
contract once the async path lands.

Scenarios:
- single_error_line_propagates_through_socketpair: one echo writes
  `test error message\n`; parent buffer matches byte-for-byte and a
  single WARN event fires with the captured payload.
- multi_error_lines_propagate_and_fire_one_warn_each: three separate
  echo calls produce three ordered lines; all three are captured in
  order and one WARN event fires per line.
- drain_returns_after_child_exit_closes_child_end: confirms the drain
  observes EOF cleanly when the subprocess exits and the child end
  closes, guarding the failure mode the design doc calls out under
  "Tokio drain task survives past child reap".

Gated `cfg(all(unix, feature = "ssh-socketpair-stderr"))` so the file
no-ops on Windows and on default builds. Adds `tracing` and
`tracing-subscriber` as dev-dependencies of `rsync_io`; a custom
`Layer` records WARN events with thread-local dispatch propagated to
the spawned drain thread.
oferchen added a commit that referenced this pull request May 18, 2026
SSE-6 from docs/design/socketpair-stderr-channel.md. Drives the SSE-3
`make_stderr_socketpair` primitive end-to-end by wiring the child end
into a real subprocess as fd 2 and asserting the parent end surfaces
the bytes verbatim. Each captured line additionally fires a
`tracing::warn!` event, mirroring the production drain shape staged
in SSE-4 (#4363) so this test continues to exercise the observable
contract once the async path lands.

Scenarios:
- single_error_line_propagates_through_socketpair: one echo writes
  `test error message\n`; parent buffer matches byte-for-byte and a
  single WARN event fires with the captured payload.
- multi_error_lines_propagate_and_fire_one_warn_each: three separate
  echo calls produce three ordered lines; all three are captured in
  order and one WARN event fires per line.
- drain_returns_after_child_exit_closes_child_end: confirms the drain
  observes EOF cleanly when the subprocess exits and the child end
  closes, guarding the failure mode the design doc calls out under
  "Tokio drain task survives past child reap".

Gated `cfg(all(unix, feature = "ssh-socketpair-stderr"))` so the file
no-ops on Windows and on default builds. Adds `tracing` and
`tracing-subscriber` as dev-dependencies of `rsync_io`; a custom
`Layer` records WARN events with thread-local dispatch propagated to
the spawned drain thread.
Implements SSE-4 from docs/design/socketpair-stderr-channel.md: when both
async-ssh and ssh-socketpair-stderr features are enabled, AsyncSshTransport
installs a socketpair-backed stderr channel and drains it via a tokio task
into a bounded 8 KiB RingBuffer, emitting tracing::warn! per line.

- New module async_stderr_drain.rs gated on both features
  - RingBuffer<const N: usize> with sliding-window semantics
  - AsyncStderrDrain::spawn(reader) wires a tokio::spawn drain loop
  - stderr_capture() snapshot accessor; join() awaits clean EOF
  - Drop aborts the task safely (it only owns reader + Arc buffer clone)
- Wire into AsyncSshTransport::execute_remote_rsync: replace Stdio::inherit
  with configure_stderr_channel when both features are enabled on Unix; fall
  back to inherit on FD exhaustion per the design doc
- AsyncSshTransport::stderr_capture() returns the bounded snapshot
- Unit tests (Unix-only): 1 KiB write/snapshot equality, multi-line
  capture, clean EOF after sender drop, capture cap enforcement, ring
  buffer math

# Conflicts:
#	crates/rsync_io/Cargo.toml
@oferchen
oferchen force-pushed the feat/ssh-async-stderr-drain branch from b5b6c97 to 9973edc Compare May 18, 2026 02:52
@oferchen
oferchen merged commit 3c09c52 into master May 18, 2026
4 of 9 checks passed
@oferchen
oferchen deleted the feat/ssh-async-stderr-drain branch May 18, 2026 02:53
oferchen added a commit that referenced this pull request May 18, 2026
SSE-6 from docs/design/socketpair-stderr-channel.md. Drives the SSE-3
`make_stderr_socketpair` primitive end-to-end by wiring the child end
into a real subprocess as fd 2 and asserting the parent end surfaces
the bytes verbatim. Each captured line additionally fires a
`tracing::warn!` event, mirroring the production drain shape staged
in SSE-4 (#4363) so this test continues to exercise the observable
contract once the async path lands.

Scenarios:
- single_error_line_propagates_through_socketpair: one echo writes
  `test error message\n`; parent buffer matches byte-for-byte and a
  single WARN event fires with the captured payload.
- multi_error_lines_propagate_and_fire_one_warn_each: three separate
  echo calls produce three ordered lines; all three are captured in
  order and one WARN event fires per line.
- drain_returns_after_child_exit_closes_child_end: confirms the drain
  observes EOF cleanly when the subprocess exits and the child end
  closes, guarding the failure mode the design doc calls out under
  "Tokio drain task survives past child reap".

Gated `cfg(all(unix, feature = "ssh-socketpair-stderr"))` so the file
no-ops on Windows and on default builds. Adds `tracing` and
`tracing-subscriber` as dev-dependencies of `rsync_io`; a custom
`Layer` records WARN events with thread-local dispatch propagated to
the spawned drain thread.
oferchen added a commit that referenced this pull request May 18, 2026
…4363)

Implements SSE-4 from docs/design/socketpair-stderr-channel.md: when both
async-ssh and ssh-socketpair-stderr features are enabled, AsyncSshTransport
installs a socketpair-backed stderr channel and drains it via a tokio task
into a bounded 8 KiB RingBuffer, emitting tracing::warn! per line.

- New module async_stderr_drain.rs gated on both features
  - RingBuffer<const N: usize> with sliding-window semantics
  - AsyncStderrDrain::spawn(reader) wires a tokio::spawn drain loop
  - stderr_capture() snapshot accessor; join() awaits clean EOF
  - Drop aborts the task safely (it only owns reader + Arc buffer clone)
- Wire into AsyncSshTransport::execute_remote_rsync: replace Stdio::inherit
  with configure_stderr_channel when both features are enabled on Unix; fall
  back to inherit on FD exhaustion per the design doc
- AsyncSshTransport::stderr_capture() returns the bounded snapshot
- Unit tests (Unix-only): 1 KiB write/snapshot equality, multi-line
  capture, clean EOF after sender drop, capture cap enforcement, ring
  buffer math

# Conflicts:
#	crates/rsync_io/Cargo.toml
oferchen added a commit that referenced this pull request May 18, 2026
SSE-6 from docs/design/socketpair-stderr-channel.md. Drives the SSE-3
`make_stderr_socketpair` primitive end-to-end by wiring the child end
into a real subprocess as fd 2 and asserting the parent end surfaces
the bytes verbatim. Each captured line additionally fires a
`tracing::warn!` event, mirroring the production drain shape staged
in SSE-4 (#4363) so this test continues to exercise the observable
contract once the async path lands.

Scenarios:
- single_error_line_propagates_through_socketpair: one echo writes
  `test error message\n`; parent buffer matches byte-for-byte and a
  single WARN event fires with the captured payload.
- multi_error_lines_propagate_and_fire_one_warn_each: three separate
  echo calls produce three ordered lines; all three are captured in
  order and one WARN event fires per line.
- drain_returns_after_child_exit_closes_child_end: confirms the drain
  observes EOF cleanly when the subprocess exits and the child end
  closes, guarding the failure mode the design doc calls out under
  "Tokio drain task survives past child reap".

Gated `cfg(all(unix, feature = "ssh-socketpair-stderr"))` so the file
no-ops on Windows and on default builds. Adds `tracing` and
`tracing-subscriber` as dev-dependencies of `rsync_io`; a custom
`Layer` records WARN events with thread-local dispatch propagated to
the spawned drain thread.
oferchen added a commit that referenced this pull request May 18, 2026
…4363)

Implements SSE-4 from docs/design/socketpair-stderr-channel.md: when both
async-ssh and ssh-socketpair-stderr features are enabled, AsyncSshTransport
installs a socketpair-backed stderr channel and drains it via a tokio task
into a bounded 8 KiB RingBuffer, emitting tracing::warn! per line.

- New module async_stderr_drain.rs gated on both features
  - RingBuffer<const N: usize> with sliding-window semantics
  - AsyncStderrDrain::spawn(reader) wires a tokio::spawn drain loop
  - stderr_capture() snapshot accessor; join() awaits clean EOF
  - Drop aborts the task safely (it only owns reader + Arc buffer clone)
- Wire into AsyncSshTransport::execute_remote_rsync: replace Stdio::inherit
  with configure_stderr_channel when both features are enabled on Unix; fall
  back to inherit on FD exhaustion per the design doc
- AsyncSshTransport::stderr_capture() returns the bounded snapshot
- Unit tests (Unix-only): 1 KiB write/snapshot equality, multi-line
  capture, clean EOF after sender drop, capture cap enforcement, ring
  buffer math

# Conflicts:
#	crates/rsync_io/Cargo.toml
oferchen added a commit that referenced this pull request Aug 24, 2026
SSE-6 from docs/design/socketpair-stderr-channel.md. Drives the SSE-3
`make_stderr_socketpair` primitive end-to-end by wiring the child end
into a real subprocess as fd 2 and asserting the parent end surfaces
the bytes verbatim. Each captured line additionally fires a
`tracing::warn!` event, mirroring the production drain shape staged
in SSE-4 (#4363) so this test continues to exercise the observable
contract once the async path lands.

Scenarios:
- single_error_line_propagates_through_socketpair: one echo writes
  `test error message\n`; parent buffer matches byte-for-byte and a
  single WARN event fires with the captured payload.
- multi_error_lines_propagate_and_fire_one_warn_each: three separate
  echo calls produce three ordered lines; all three are captured in
  order and one WARN event fires per line.
- drain_returns_after_child_exit_closes_child_end: confirms the drain
  observes EOF cleanly when the subprocess exits and the child end
  closes, guarding the failure mode the design doc calls out under
  "Tokio drain task survives past child reap".

Gated `cfg(all(unix, feature = "ssh-socketpair-stderr"))` so the file
no-ops on Windows and on default builds. Adds `tracing` and
`tracing-subscriber` as dev-dependencies of `rsync_io`; a custom
`Layer` records WARN events with thread-local dispatch propagated to
the spawned drain thread.
oferchen added a commit that referenced this pull request Aug 24, 2026
…4363)

Implements SSE-4 from docs/design/socketpair-stderr-channel.md: when both
async-ssh and ssh-socketpair-stderr features are enabled, AsyncSshTransport
installs a socketpair-backed stderr channel and drains it via a tokio task
into a bounded 8 KiB RingBuffer, emitting tracing::warn! per line.

- New module async_stderr_drain.rs gated on both features
  - RingBuffer<const N: usize> with sliding-window semantics
  - AsyncStderrDrain::spawn(reader) wires a tokio::spawn drain loop
  - stderr_capture() snapshot accessor; join() awaits clean EOF
  - Drop aborts the task safely (it only owns reader + Arc buffer clone)
- Wire into AsyncSshTransport::execute_remote_rsync: replace Stdio::inherit
  with configure_stderr_channel when both features are enabled on Unix; fall
  back to inherit on FD exhaustion per the design doc
- AsyncSshTransport::stderr_capture() returns the bounded snapshot
- Unit tests (Unix-only): 1 KiB write/snapshot equality, multi-line
  capture, clean EOF after sender drop, capture cap enforcement, ring
  buffer math

# Conflicts:
#	crates/rsync_io/Cargo.toml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant