Skip to content

feat: add SSH stderr aux channel trait with socketpair impl on Unix - #3383

Merged
oferchen merged 2 commits into
masterfrom
feat/ssh-stderr-socketpair
Apr 25, 2026
Merged

oferchen merged 2 commits into
masterfrom
feat/ssh-stderr-socketpair

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Closes #1689

Summary

Introduces a StderrAuxChannel trait abstraction over the SSH subprocess's stderr drain, so the connection layer no longer needs to know which kernel object backs the channel.

Two implementations:

  • PipeStderrChannel - cross-platform, wraps the conventional Stdio::piped() ChildStderr.
  • SocketpairStderrChannel - Unix-only, reads the parent half of UnixStream::pair() while the child end is handed to the subprocess as its stderr file descriptor.

SshCommand::spawn attempts the socketpair path first on Unix and falls back to the pipe path on failure (e.g., FD exhaustion). Windows always uses the pipe path.

SshConnection and SshChildHandle hold Option<Box<dyn StderrAuxChannel + Send>>, exposing the same collected()/join()/join_and_surface_on_error() semantics as before.

The socketpair endpoint exposes a real pollable file descriptor that future event-loop integrations can register with poll(2)/epoll(7)/kqueue(2) without touching call sites in connection.rs.

Safety

The conversion from UnixStream to Stdio uses the safe stdlib path UnixStream -> OwnedFd -> Stdio, so no unsafe is needed (the crate keeps #![deny(unsafe_code)]).

Files

  • crates/rsync_io/src/ssh/aux_channel.rs (NEW) - trait + both impls + factories + tests
  • crates/rsync_io/src/ssh/builder.rs - spawn() calls configure_stderr_channel + build_stderr_channel
  • crates/rsync_io/src/ssh/connection.rs - StderrDrain struct removed, replaced by Option<BoxedStderrChannel> field
  • crates/rsync_io/src/ssh/mod.rs - declares mod aux_channel
  • crates/rsync_io/src/ssh/tests.rs - stale StderrDrain comments updated

Net: +690 / -163 across 5 files.

Test plan

  • cargo nextest run -p rsync_io --all-features (CI)
  • Inline tests cover: stderr collection, non-UTF-8 handling, concurrent collected() snapshots, bounded 64 KiB sliding-window buffer, idempotent join, silent-on-success default behavior, both factory dispatch paths.
  • Existing SSH integration tests remain green.

Introduce StderrAuxChannel trait abstraction with two implementations:
PipeStderrChannel (cross-platform, anonymous-pipe backed) and
SocketpairStderrChannel (Unix-only, socketpair(2) backed). SshCommand::spawn
attempts socketpair first on Unix and falls back to a pipe on any error;
non-Unix targets always use the pipe path. SshConnection and SshChildHandle
now hold a Box<dyn StderrAuxChannel + Send> so callers do not need to know
which kernel object backs the drain. The socketpair endpoint exposes a real
file descriptor that future event-loop integrations can register with poll(2)
without disturbing call sites in connection.rs.
@github-actions github-actions Bot added the enhancement New feature or request label Apr 25, 2026
@oferchen
oferchen merged commit bb24856 into master Apr 25, 2026
33 of 41 checks passed
@oferchen
oferchen deleted the feat/ssh-stderr-socketpair branch April 25, 2026 19:03
oferchen added a commit that referenced this pull request May 1, 2026
…3383)

* feat: add SSH stderr aux channel trait with socketpair impl on Unix

Introduce StderrAuxChannel trait abstraction with two implementations:
PipeStderrChannel (cross-platform, anonymous-pipe backed) and
SocketpairStderrChannel (Unix-only, socketpair(2) backed). SshCommand::spawn
attempts socketpair first on Unix and falls back to a pipe on any error;
non-Unix targets always use the pipe path. SshConnection and SshChildHandle
now hold a Box<dyn StderrAuxChannel + Send> so callers do not need to know
which kernel object backs the drain. The socketpair endpoint exposes a real
file descriptor that future event-loop integrations can register with poll(2)
without disturbing call sites in connection.rs.

* fix: import Stdio in ssh::builder for command stdin/stdout config
oferchen added a commit that referenced this pull request May 1, 2026
…nsport (#1938) (#3525)

Formalizes the SSH stdio transport audit at docs/audits/ssh-socketpair-vs-pipes.md
under tracker #1938, consolidating prior #1686 working notes (PR #3438), the
io_uring boundary documented for #1858 (PR #3418), and the stderr socketpair
shipped under #1689 (PR #3383). Restructures the document into the formal
seven-section layout (summary, upstream reference, current implementation,
trade-offs, decision matrix, recommendation, implementation notes) plus
findings and references.

Recommends keeping anonymous pipes for the SSH wire and not pursuing the
socketpair migration: splice(2) and vmsplice(2) require a pipe end, the
zero-copy plan in #1860 depends on that, and the unified-FD argument is
subsumed by the async-transport refactor (#2068, #1655). Closes #1687
(prototype socketpair wire) as do-not-implement and #1902 (verify wire
claim against rsync_io source) as verified.

Citations were re-checked against worktree source: builder.rs:300-301
(Stdio::piped on the wire), aux_channel.rs:263-285 (UnixStream::pair for
stderr, Unix only), connection.rs:30-39 (SshConnection struct),
mod.rs:57-75 (io_uring boundary). Upstream evidence verified against
target/interop/upstream-src/rsync-3.4.1/: pipe.c:48-97 (piped_child),
util1.c:74-96 (fd_pair), main.c:504-663 (do_cmd dispatch),
clientserver.c:116-148 (daemon TCP wire), socket.c:736-846 (sock_exec
test escape).
oferchen added a commit that referenced this pull request May 5, 2026
…3383)

* feat: add SSH stderr aux channel trait with socketpair impl on Unix

Introduce StderrAuxChannel trait abstraction with two implementations:
PipeStderrChannel (cross-platform, anonymous-pipe backed) and
SocketpairStderrChannel (Unix-only, socketpair(2) backed). SshCommand::spawn
attempts socketpair first on Unix and falls back to a pipe on any error;
non-Unix targets always use the pipe path. SshConnection and SshChildHandle
now hold a Box<dyn StderrAuxChannel + Send> so callers do not need to know
which kernel object backs the drain. The socketpair endpoint exposes a real
file descriptor that future event-loop integrations can register with poll(2)
without disturbing call sites in connection.rs.

* fix: import Stdio in ssh::builder for command stdin/stdout config
oferchen added a commit that referenced this pull request May 5, 2026
…nsport (#1938) (#3525)

Formalizes the SSH stdio transport audit at docs/audits/ssh-socketpair-vs-pipes.md
under tracker #1938, consolidating prior #1686 working notes (PR #3438), the
io_uring boundary documented for #1858 (PR #3418), and the stderr socketpair
shipped under #1689 (PR #3383). Restructures the document into the formal
seven-section layout (summary, upstream reference, current implementation,
trade-offs, decision matrix, recommendation, implementation notes) plus
findings and references.

Recommends keeping anonymous pipes for the SSH wire and not pursuing the
socketpair migration: splice(2) and vmsplice(2) require a pipe end, the
zero-copy plan in #1860 depends on that, and the unified-FD argument is
subsumed by the async-transport refactor (#2068, #1655). Closes #1687
(prototype socketpair wire) as do-not-implement and #1902 (verify wire
claim against rsync_io source) as verified.

Citations were re-checked against worktree source: builder.rs:300-301
(Stdio::piped on the wire), aux_channel.rs:263-285 (UnixStream::pair for
stderr, Unix only), connection.rs:30-39 (SshConnection struct),
mod.rs:57-75 (io_uring boundary). Upstream evidence verified against
target/interop/upstream-src/rsync-3.4.1/: pipe.c:48-97 (piped_child),
util1.c:74-96 (fd_pair), main.c:504-663 (do_cmd dispatch),
clientserver.c:116-148 (daemon TCP wire), socket.c:736-846 (sock_exec
test escape).
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