Skip to content

docs(audits): SSH stderr socketpair-to-pipe fallback sites (SSF-1) - #4658

Merged
oferchen merged 1 commit into
masterfrom
docs/audits/ssf-1-socketpair-fallback-sites
May 21, 2026
Merged

oferchen merged 1 commit into
masterfrom
docs/audits/ssf-1-socketpair-fallback-sites

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Inventory of all SSH stderr socketpair-to-pipe fallback branches in crates/rsync_io/src/ssh/: 8 code-level branching sites plus 2 propagation-only struct fields and 1 confirmed non-site (embedded russh).
  • Splits compile-time fallbacks (feature gate, non-Unix #[cfg]) from runtime fallbacks (socketpair(2) rejection, try_clone failure, async-path Stdio::inherit degradation).
  • Recommends 3 sites for SSF-2 one-shot warnings: aux_channel.rs:349-358 (sync runtime fallback), aux_channel.rs:223 (half-fallback on try_clone), async_transport.rs:150-153 (async runtime fallback to Stdio::inherit). Excludes async_transport.rs:185-186 because that path already surfaces errors via ?.

Test plan

  • Doc-only change; no code touched.
  • All file:line citations verified against current master HEAD.
  • Cross-checked compile-time vs runtime classification against Cargo.toml feature definitions and #[cfg] gates.
  • Confirmed embedded russh transport (embedded/sync_bridge.rs) carries no socketpair branch.

Inventory every branch in `crates/rsync_io/src/ssh/` where the stderr
channel picks between socketpair and anonymous-pipe backends, including
compile-time feature gates, runtime kernel rejections, and half-fallback
edges. Sets up SSF-2 by identifying the runtime-only sites that should
emit a one-shot operator warning.
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label May 21, 2026
@oferchen
oferchen merged commit ac3aee9 into master May 21, 2026
10 checks passed
oferchen added a commit that referenced this pull request May 21, 2026
Surfaces the three SSH stderr fallback transitions identified in the
SSF-1 audit (PR #4658) as one-shot operator-facing warnings so the
async-drain degradation is no longer silent.

Sites covered:
- aux_channel.rs site 1 (sync `configure_stderr_channel`): the Unix arm
  could not allocate a `socketpair(2)` and is falling back to a pipe
  via `Stdio::piped()`. Upgraded from `debug_log!` to an `eprintln!`
  through the new `warn_once` helper.
- aux_channel.rs site 2 (`SocketpairStderrChannel::spawn`): the
  `try_clone` for `shutdown_read` failed; the channel still drains but
  shutdown_read becomes a no-op. New warning calls out the
  session-shutdown delay risk.
- async_transport.rs site 3 (`AsyncSshTransport::spawn`): when
  configure_stderr_channel returned None, the async path additionally
  drops to `Stdio::inherit()`, so `stderr_capture()` returns empty for
  the rest of the session. Emitted via `tracing::warn!` because the
  call site is already inside the `ssh-socketpair-stderr` feature where
  tracing is in scope; the default-build sync path stays on `eprintln!`
  to avoid pulling tracing into default features.

Each site owns its own `OnceLock<()>` so the warning fires at most once
per process even when rsync re-establishes SSH multiple times in a
session (push+pull, resumes, multi-host loops). Operator-grep markers
are exposed as `pub(super) const` so tests + log greps share the same
substring.

Tests:
- `warns_once_on_sync_socketpair_rejection` drives the site-1 helper
  through a local OnceLock to assert one-shot discipline.
- `warns_once_on_half_fallback` does the same for site 2.
- `warn_once_helper_is_thread_safe` exercises 8 concurrent callers
  through `thread::scope` and asserts exactly one emission + exactly
  one non-empty sink.
- `warns_once_on_async_fallback` (feature-gated) installs a scoped
  `tracing` subscriber that captures `target = "ssh::stderr"` events
  to assert the site-3 message + discipline without coordinating with
  the process-wide static.

SSF-1 audit reference: docs/audits/ssf-1-socketpair-fallback-sites-2026-05-21.md
@oferchen
oferchen deleted the docs/audits/ssf-1-socketpair-fallback-sites branch May 21, 2026 14:09
oferchen added a commit that referenced this pull request May 21, 2026
#4663)

* feat(rsync_io): warn on SSH stderr socketpair-to-pipe fallback (SSF-2)

Surfaces the three SSH stderr fallback transitions identified in the
SSF-1 audit (PR #4658) as one-shot operator-facing warnings so the
async-drain degradation is no longer silent.

Sites covered:
- aux_channel.rs site 1 (sync `configure_stderr_channel`): the Unix arm
  could not allocate a `socketpair(2)` and is falling back to a pipe
  via `Stdio::piped()`. Upgraded from `debug_log!` to an `eprintln!`
  through the new `warn_once` helper.
- aux_channel.rs site 2 (`SocketpairStderrChannel::spawn`): the
  `try_clone` for `shutdown_read` failed; the channel still drains but
  shutdown_read becomes a no-op. New warning calls out the
  session-shutdown delay risk.
- async_transport.rs site 3 (`AsyncSshTransport::spawn`): when
  configure_stderr_channel returned None, the async path additionally
  drops to `Stdio::inherit()`, so `stderr_capture()` returns empty for
  the rest of the session. Emitted via `tracing::warn!` because the
  call site is already inside the `ssh-socketpair-stderr` feature where
  tracing is in scope; the default-build sync path stays on `eprintln!`
  to avoid pulling tracing into default features.

Each site owns its own `OnceLock<()>` so the warning fires at most once
per process even when rsync re-establishes SSH multiple times in a
session (push+pull, resumes, multi-host loops). Operator-grep markers
are exposed as `pub(super) const` so tests + log greps share the same
substring.

Tests:
- `warns_once_on_sync_socketpair_rejection` drives the site-1 helper
  through a local OnceLock to assert one-shot discipline.
- `warns_once_on_half_fallback` does the same for site 2.
- `warn_once_helper_is_thread_safe` exercises 8 concurrent callers
  through `thread::scope` and asserts exactly one emission + exactly
  one non-empty sink.
- `warns_once_on_async_fallback` (feature-gated) installs a scoped
  `tracing` subscriber that captures `target = "ssh::stderr"` events
  to assert the site-3 message + discipline without coordinating with
  the process-wide static.

SSF-1 audit reference: docs/audits/ssf-1-socketpair-fallback-sites-2026-05-21.md

* style(rsync_io): apply rustfmt to SSF-2 warning helpers

Address the 8 rustfmt diffs CI surfaced on PR #4663: collapsed
import order, single-line function signatures and call sites that
fit, multi-line `assert!` blocks where rustfmt prefers them.

Behaviour-neutral — no source semantics change.

* fix(rsync_io): drop brittle tracing subscriber capture in async-fallback test

The custom tracing CaptureLayer captured 0 events under nextest. The
local_lock first/second return values already prove the OnceLock
discipline. Replaced the scoped-subscriber test body with the simpler
"first emits, second suppresses" assertion plus a substring check on
the marker constant. Marker text is the operator-facing contract;
the constant being correct guarantees the payload is correct because
the production helper formats it via `tracing::warn!(... "warning: {MARKER}. ...")`.

* fix(rsync_io): gate SSF-2 warn helpers behind cfg(unix)

warn_once, emit_socketpair_rejection_warning, and the two marker
constants are only reachable from #[cfg(unix)] sites (socketpair is
Unix-only). On Windows builds they became dead code, tripping
-D warnings. Added matching #[cfg(unix)] gates so the helpers
compile only when reachable. Tests that exercise these helpers are
also #[cfg(unix)], so visibility is preserved on Unix test runs.

* fix(rsync_io): gate fmt/Write/OnceLock imports behind cfg(unix)

Followup to the prior gate of warn_once + emit_socketpair_rejection_warning
+ MARKER consts: those helpers' only consumers were already cfg(unix),
so on Windows the std::fmt / std::io::Write / std::sync::OnceLock imports
became dead. Split each into a cfg(unix)-gated re-import.
oferchen added a commit that referenced this pull request Aug 24, 2026
…4658)

Inventory every branch in `crates/rsync_io/src/ssh/` where the stderr
channel picks between socketpair and anonymous-pipe backends, including
compile-time feature gates, runtime kernel rejections, and half-fallback
edges. Sets up SSF-2 by identifying the runtime-only sites that should
emit a one-shot operator warning.
oferchen added a commit that referenced this pull request Aug 24, 2026
#4663)

* feat(rsync_io): warn on SSH stderr socketpair-to-pipe fallback (SSF-2)

Surfaces the three SSH stderr fallback transitions identified in the
SSF-1 audit (PR #4658) as one-shot operator-facing warnings so the
async-drain degradation is no longer silent.

Sites covered:
- aux_channel.rs site 1 (sync `configure_stderr_channel`): the Unix arm
  could not allocate a `socketpair(2)` and is falling back to a pipe
  via `Stdio::piped()`. Upgraded from `debug_log!` to an `eprintln!`
  through the new `warn_once` helper.
- aux_channel.rs site 2 (`SocketpairStderrChannel::spawn`): the
  `try_clone` for `shutdown_read` failed; the channel still drains but
  shutdown_read becomes a no-op. New warning calls out the
  session-shutdown delay risk.
- async_transport.rs site 3 (`AsyncSshTransport::spawn`): when
  configure_stderr_channel returned None, the async path additionally
  drops to `Stdio::inherit()`, so `stderr_capture()` returns empty for
  the rest of the session. Emitted via `tracing::warn!` because the
  call site is already inside the `ssh-socketpair-stderr` feature where
  tracing is in scope; the default-build sync path stays on `eprintln!`
  to avoid pulling tracing into default features.

Each site owns its own `OnceLock<()>` so the warning fires at most once
per process even when rsync re-establishes SSH multiple times in a
session (push+pull, resumes, multi-host loops). Operator-grep markers
are exposed as `pub(super) const` so tests + log greps share the same
substring.

Tests:
- `warns_once_on_sync_socketpair_rejection` drives the site-1 helper
  through a local OnceLock to assert one-shot discipline.
- `warns_once_on_half_fallback` does the same for site 2.
- `warn_once_helper_is_thread_safe` exercises 8 concurrent callers
  through `thread::scope` and asserts exactly one emission + exactly
  one non-empty sink.
- `warns_once_on_async_fallback` (feature-gated) installs a scoped
  `tracing` subscriber that captures `target = "ssh::stderr"` events
  to assert the site-3 message + discipline without coordinating with
  the process-wide static.

SSF-1 audit reference: docs/audits/ssf-1-socketpair-fallback-sites-2026-05-21.md

* style(rsync_io): apply rustfmt to SSF-2 warning helpers

Address the 8 rustfmt diffs CI surfaced on PR #4663: collapsed
import order, single-line function signatures and call sites that
fit, multi-line `assert!` blocks where rustfmt prefers them.

Behaviour-neutral — no source semantics change.

* fix(rsync_io): drop brittle tracing subscriber capture in async-fallback test

The custom tracing CaptureLayer captured 0 events under nextest. The
local_lock first/second return values already prove the OnceLock
discipline. Replaced the scoped-subscriber test body with the simpler
"first emits, second suppresses" assertion plus a substring check on
the marker constant. Marker text is the operator-facing contract;
the constant being correct guarantees the payload is correct because
the production helper formats it via `tracing::warn!(... "warning: {MARKER}. ...")`.

* fix(rsync_io): gate SSF-2 warn helpers behind cfg(unix)

warn_once, emit_socketpair_rejection_warning, and the two marker
constants are only reachable from #[cfg(unix)] sites (socketpair is
Unix-only). On Windows builds they became dead code, tripping
-D warnings. Added matching #[cfg(unix)] gates so the helpers
compile only when reachable. Tests that exercise these helpers are
also #[cfg(unix)], so visibility is preserved on Unix test runs.

* fix(rsync_io): gate fmt/Write/OnceLock imports behind cfg(unix)

Followup to the prior gate of warn_once + emit_socketpair_rejection_warning
+ MARKER consts: those helpers' only consumers were already cfg(unix),
so on Windows the std::fmt / std::io::Write / std::sync::OnceLock imports
became dead. Split each into a cfg(unix)-gated re-import.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant