Skip to content

fix: QUIC in the default build with Retry under load, bwlimit sleep like upstream - #8229

Merged
oferchen merged 26 commits into
masterfrom
refactor/bwlimit-sleep-like-upstream
Oct 21, 2026
Merged

oferchen merged 26 commits into
masterfrom
refactor/bwlimit-sleep-like-upstream

Conversation

@oferchen

@oferchen oferchen commented Oct 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

bwlimit sleep and deterministic timing tests

  • Bandwidth limiter now sleeps the way upstream does.
    • Upstream io.c:2323-2356 sleep_for_bwlimit() sleeps only once the owed delay reaches 100 ms, then blocks in select(). oc keeps the same MINIMUM_SLEEP_MICROS floor, so the macOS kqueue EVFILT_TIMER sleeper never used its sub-millisecond resolution.
    • This removes fast_io::TimerSleeper, the limiter backend switch and OC_RSYNC_BWLIMIT_BACKEND. --bwlimit now sleeps with std::thread::sleep (nanosleep) on every platform.
    • bandwidth no longer depends on fast_io.
  • Wall-clock timing assertions are now deterministic. Elapsed-time upper bounds fail on a loaded runner, so they are replaced with:
    • exact durations on tokio's paused clock;
    • read counts instead of sleeping to a deadline;
    • waiting on an event (a killed child closing its pipe) instead of sleeping past a timeout;
    • unbounded or hour-long budgets where a regression would hang, so the harness timeout is the guard;
    • nothing at all, where a returned value, exit code or typed error already implies the bound.
  • Readiness timeouts are now constructor parameters (test seam). poll_ready takes a PollTimeout and KqueueAcceptEngine::new takes Option<Duration>.
    • Production passes the same 50 ms / 100 ms signal-check cadence as before.
    • Tests pass "no timeout", so only real readiness can end the wait. A sleep-then-probe regression now hangs instead of passing slowly.
    • Elsewhere the existing seams were enough:
      • the QUIC un-throttled control uses the bandwidth limiter's recorded-sleep session;
      • the SSH connect watchdog is checked through its latched TimedOut.
  • Perf budgets dropped from correctness tests. Time limits in the sparse copy, flist sort, signature and matching tests were removed. Perf regressions are caught by the benches and the per-PR perf gate, not by correctness tests. The same applies to the QUIC teardown latency bound: the driver's 100 ms MAX_SLEEP keeps teardown bounded, so the bound measured latency only.
  • Unblocks refactor(ssh): pass ssh stderr through like upstream #8224's macOS job. Its flake was the kqueue timer test this PR removes.
  • Diagnostic log uploads in CI no longer fail a passing job.

QUIC hardening and disk-error drain

  • Fix a deadlock in the disk-commit thread. A disk error on one file (ENOSPC, a failed open, an inplace backup or an --append-verify prefix read) used to return without draining that file's queued chunks. The network thread then blocked on a full channel forever: the daemon worker hung and a QUIC push stalled into a timeout. Every pre-commit error exit now drains, as upstream's discard_receive_data() does (receiver.c:1254-1261).
  • Harden the QUIC daemon. It refuses to start when its key doesn't match its certificate, and a Windows daemon refuses QUIC directives instead of ignoring them.
  • Ship QUIC in release artifacts (including musl), list --quic-cert and --quic-key in --help, and pin the certificate validation matrix with tests that mint their certificates with rcgen at run time.

QUIC in the default build, Retry under load, quic address

  • quic joins the default cargo features (next to embedded-ssh). Runtime stays admin opt-in, as SMB over QUIC does: a client uses QUIC only for quic:// or --quic, and a daemon listens only when quic cert file and quic key file are set. A --no-default-features build refuses quic:// and --quic with "not compiled into this build". Measured cost (Linux x86_64 release): 15,355,480 to 17,165,920 bytes (+1.81 MB, +11.8%), 406 to 420 crates.
  • Retry under load: rsync_io::quic::admission adds a RetryPolicy { Never, UnderLoad { threshold }, Always } with a pure admit(validated, handshaking) decision, driven by the new global directive quic retry = auto|always|never (default auto). The threshold is 100 in-flight handshakes, HAProxy's tune.quic.retry-threshold default. MsQuic (SMB over QUIC) and HAProxy both default to Retry under load; quinn never sends Retry on its own (Incoming::retry()), and RFC 9000's mandatory 3x anti-amplification limit stops reflection, not state exhaustion. Tokens use quinn's 15 s lifetime and per-process key.
  • Bounded incoming state: max_incoming = min(max connections, 128), 64 KiB per attempt, at most 8 MiB in total (quinn's defaults are 65536 / 10 MiB / 100 MiB).
  • quic address = <ip> [<ip> ...]: a global-only list of literal IPv4/IPv6 addresses that binds the QUIC listener independently of TCP address, e.g. quic address = 127.0.0.1 ::1 for a dual-stack loopback listener. Unset, QUIC keeps following the TCP addresses, which are dual-stack ([::] and 0.0.0.0) with a per-family fallback. A listed address that fails to bind stops the daemon and names the address. Hostnames, bad IPs, duplicates and module-scope use are refused; a Windows daemon refuses it like the other quic * directives.
  • QUIC daemon tests wait on log lines as events (test_support::LogLines, a blocking read of the daemon's stderr log), replacing a polled file with a deadline. They wait for the IPv4 "serving on" line specifically, fixing a latent race.

Details

QUIC hardening and disk-error drain

Disk-error drain

crates/transfer/src/disk_commit/process/file_ops.rs: the five error exits that returned Err(err) directly now go through discard_file_messages(), which consumes the file's remaining Chunk/MatchedChunk/SkipMatched messages up to its Commit. Buffers go back to the network thread, and the first error is reported. The open-failure exit already did this.

Evidence (physical Linux host, against /usr/bin/rsync 3.5.1):

Mutation check. All five sites were reverted to a bare return Err(err).

Unit tests:

Test With fix Mutant
disk_commit::tests::setup_error_drains_the_files_remaining_messages pass FAIL
disk_commit::tests::chunk_write_error_drains_the_files_remaining_messages pass FAIL

End to end: a push into a daemon module on a 1 MiB tmpfs, so the receiver hits ENOSPC. "Leftover workers" counts daemon children beyond the one an idle daemon always has.

Source Transport Fixed: exit, time Fixed: leftover workers Mutant Upstream 3.5.1
1 x 4 MiB TCP 11, 0.1 s 0 11, worker deadlocked 11
1 x 4 MiB QUIC 11, 0.4 s 0 11 -
200 x 64 KiB TCP 11, 0.1 s 0 11, worker deadlocked 11
1 x 64 MiB TCP 11, 0.3 s 0 11, worker deadlocked 11
1 x 64 MiB QUIC 11, 1.5 s 0 23, timed out after about 30 s -

Each mutant worker that deadlocked stayed alive for 10+ minutes, with both its main thread and its disk-commit thread parked in futex_do_wait. It survived the daemon's shutdown signal and had to be killed by PID. With the fix, every run exits promptly with upstream's code, 11 (RERR_FILEIO).

QUIC daemon identity and platform refusals

  • crates/daemon/src/daemon/runtime_options/quic_identity.rs: the daemon loads quic cert file and quic key file, checks that the key matches the leaf certificate, and exits 1 at startup if it doesn't. Without the check, the listener would come up and fail every handshake.
  • runtime_options/parsing.rs: a Windows daemon refuses any quic * directive with a clear error, since the QUIC daemon is not supported there.

Release artifacts, help and docs

  • .github/workflows/ci.yml and release-cross.yml build the quic feature into release artifacts and the musl build.
  • --help lists --quic-cert/--quic-key. The environment reference documents OC_RSYNC_QUIC_CC and OC_RSYNC_QUIC_WINDOW.

Certificate validation matrix

crates/transfer/tests/quic_certificate_validation_matrix.rs (with quic_daemon_identity_mismatch_fails_startup.rs, 32 tests) covers:

  • server leaf, IP and DNS SAN cases;
  • expired leaves;
  • mTLS: a missing client certificate, a client certificate from the wrong CA, and a missing client-auth EKU;
  • client and daemon configuration refusals.

Validity windows come from the clock. Keys are generated with rcgen per run. tools/ci/check_no_key_material.py fails CI if PEM key or certificate material is committed.

Test plan

bwlimit sleep and deterministic timing tests

  • CI: fmt + clippy, nextest (stable), Windows, macOS, Linux musl.

  • Local gates (Linux):

    • fmt and check_rustfmt_all.py;
    • clippy --all-targets --all-features -D warnings on every touched crate;
    • Windows-gnu clippy for bandwidth, fast_io, signature, matching and test-support;
    • dead_code_census, unsafe_owner_deps, no-placeholders.
  • macOS is gated by CI only: the kqueue engine and the fast_io kqueue module cannot be cross-built here (jemalloc's C build).

  • Targeted nextest passes, including --features quic and embedded-ssh. The networked SSH watchdog test also passes with OC_RSYNC_SSH_NET=1.

  • Mutation checks; each mutation turns its test red:

    Mutation Red tests
    Async limiter sleeps twice as long 3
    Async limiter burst cap removed 1
    Daemon token bucket always sleeps 1
    Receiver retries the goodbye read 3
    poll_ready ignores readiness 1
    QUIC throttled_writer drops the limiter 1
    QUIC un-throttled path gets a limiter 1
    Connect watchdog never latches fired 3
  • The reworked daemon, QUIC and SSH tests passed 30/30 runs with every core busy.

  • Daemon accept syscall gate (strace -c, 20 connections), before and after the seam: 21 accept4, 23 poll and 42 ppoll each, with totals of 3147 and 3150 (idle noise).

  • --bwlimit=500K on a 2 MiB local copy: 4.020 s over 3 runs, against 4.096 s expected (-1.9%). strace showed 112 clock_nanosleep. Linux already used the std backend, so its syscall profile does not change.

QUIC hardening and disk-error drain

  • cargo fmt --all -- --check and python3 tools/ci/check_rustfmt_all.py
  • cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings
  • cargo check --target x86_64-pc-windows-gnu -p daemon -p cli -p transfer -p rsync_io --all-features --tests
  • cargo nextest run -p transfer -p daemon -p cli -p rsync_io -p test-support --all-features -E 'test(/quic|drain|help|runtime_options|disk_commit/)': 756 passed
  • cargo nextest run -p transfer --all-features -E 'binary(quic_certificate_validation_matrix) | binary(quic_daemon_identity_mismatch_fails_startup) | test(/disk_commit::/)': 184 passed (32 QUIC integration tests)
  • Disk-error drain mutation: unit tests red under the mutant; the ENOSPC end-to-end runs above
  • python3 tools/ci/check_no_key_material.py, unsafe_owner_deps.py, dead_code_census.py, cargo run --locked -p xtask -- no-placeholders, cargo run --locked -p xtask -- citations
  • Upstream testsuite 3.5.1 (nonroot leg) against tools/ci/upstream-3.5.1-expect.nonroot.txt, on the physical Linux host. Branch and master (0fe3a72) give the identical result: 274 passed, 1 failed, 85 skipped. Both carry the same two host-only manifest mismatches: protected-regular passes where the manifest expects a skip (the host has fs.protected_regular=1), and rrsync-userns-procfs fails. No regression.
  • CI: fmt + clippy, nextest (stable), Windows, macOS, Linux musl

QUIC default build, Retry and quic address

  • Unit tests for the admission policy at the threshold boundary; a loopback test that always sends a Retry and still completes; a ServerConfig test that the incoming limits are applied; parse tests for quic retry and quic address; resolver tests (set vs unset, unset stays dual-stack).
  • End-to-end: a daemon pull under quic retry = always logs the Retry line, and under never does not. TCP on the wildcard with QUIC on 127.0.0.1 ::1, where the bound-address log line equals the configured list.
  • Mutation checks (10), each failing its test: >= to >, Always forced to accept, max_incoming ignored, limits not applied, directive dropped, admission unwired; quic address ignored, explicit bind failure tolerated, duplicate check removed, bad entries accepted. Readiness: a 12 s delay in the QUIC front still passes.
  • docs/quic-transport.md walkthrough on a DEFAULT build: 18/18. With quic address = 127.0.0.1 ::1, ss -ulpn shows UDP only on 127.0.0.1 and ::1 while TCP stays on both wildcards.
  • Windows-gnu cargo check --workspace --all-features --tests, both clippy runs (all features and default features), --no-default-features check, 684 targeted tests on the rebased tree.

Coordination

bwlimit sleep and deterministic timing tests

QUIC hardening and disk-error drain

Conventional commit prefix

  • fix: - QUIC daemon refusals and the disk-error drain are fixes; the bwlimit sleeper removal and test rewrites ride along as refactor/test work.

Security considerations

bwlimit sleep and deterministic timing tests

  • Threat surface affected: daemon accept loop only. poll_ready and the macOS kqueue accept engine now take their wait bound as a parameter; production passes the same 50 ms / 100 ms as before, so accept, timeout and shutdown behaviour is unchanged.
  • Mitigations / tests added: the daemon accept tests wait on a real connection instead of a wall-clock bound; daemon accept syscall counts are unchanged.
  • Cross-references: none (no SECURITY.md change).

QUIC hardening and disk-error drain

  • Threat surface affected: the QUIC daemon's TLS identity, and daemon worker liveness under disk errors.
  • Mitigations / tests added:
    • Mismatched identity: a daemon whose key doesn't match its certificate now fails closed at startup (daemon_cert_and_key_mismatch_exits_1, quic_daemon_identity_mismatch_fails_startup).
    • Windows: a daemon refuses QUIC directives rather than starting without the operator's intended transport (runtime_options_quic_windows_refusal).
    • mTLS: the validation matrix pins refusal of wrong-CA, expired and EKU-less client certificates.
    • Liveness: a client can no longer pin a daemon worker forever by filling the destination, which closes a resource-exhaustion path for daemon operators.
  • Cross-references: docs/quic-transport.md, SECURITY.md.

Pre-merge checklist

  • Conventional commit prefix on PR title matches the change category.
  • cargo fmt --all run locally.
  • CHANGELOG.md updated if user-visible (Removed: the env var and the kqueue sleeper; replace #8229 once the PR number is known).
  • SECURITY.md updated if security-relevant. Not applicable.
  • No references to internal tooling or non-human authoring aids; hyphens, not em-dashes.

…eue sleeper

The bandwidth limiter only sleeps once the owed delay reaches 100 ms
(upstream io.c:2323-2356 sleep_for_bwlimit, which then blocks in select()),
so the kqueue EVFILT_TIMER sleeper never used its sub-millisecond
resolution. Remove fast_io::TimerSleeper, the limiter backend switch and
the OC_RSYNC_BWLIMIT_BACKEND selector, and sleep with std::thread::sleep
on every platform. bandwidth no longer depends on fast_io.
Replace elapsed-time upper bounds, which fail on a loaded runner, with
checks whose outcome cannot depend on scheduling:

- AsyncRateLimiter tests run on tokio's paused clock and assert exact
  virtual durations and token counts.
- The goodbye timeout fixture counts the reads issued after the prefix
  instead of sleeping to a deadline, so "waited once" and "did not
  retry" are exact counts.
- Waits that a regression would turn into an unbounded block now use an
  unbounded or hour-long budget, so the harness timeout is the guard.
- Assertions already implied by a returned value, an exit code or a
  typed error are removed, as are perf budgets in correctness tests.
The testsuite and interop log uploads are diagnostics no later job
downloads. A GitHub artifact ETIMEDOUT after every cell passed was
failing the job. Build, release, fuzz and benchmark uploads stay fatal.
poll_ready takes its PollTimeout and KqueueAcceptEngine::new its kevent
wait bound instead of reading a constant. Production passes the same
50 ms / 100 ms signal-check cadence. The readiness tests pass no bound
at all, so only a real connection can end the wait: a sleep-then-probe
regression now hangs the test instead of passing slowly under a
wall-clock ceiling.
- The un-throttled QUIC control checks the limiter's recorded-sleep
  session is empty instead of a wall-clock ceiling; both pacing tests
  assert whether the writer carries a limiter.
- The QUIC teardown latency bound is dropped: the driver's 100 ms
  MAX_SLEEP keeps teardown bounded, so it only measured latency, which
  the benches and perf gate own.
- The connect-watchdog tests block on the killed child closing its
  stdout instead of sleeping past the timeout, and the networked smoke
  test checks the latched TimedOut rather than elapsed time.
- ThrottlingWriter::is_throttled now has a caller; drop its stale
  dead-code allowlist row.
The daemon loaded its QUIC identity only when the QUIC front process
started. A cert/key mismatch was logged and the daemon kept serving
TCP with no QUIC listener, so the operator could not tell QUIC was
down. Load the identity at startup with the other QUIC config checks
and exit 1, the same as a missing cert or key. rustls reports the
mismatch as KeyMismatch; the error now says the private key does not
match the certificate.
The QUIC listener runs in a forked front process and exists only on
Unix. A Windows daemon with a quic directive started TCP-only and
gave no sign that QUIC was ignored. It now fails config parsing with
exit 1 and names the directive. The Windows CI job runs the test.
Release builds for Linux gnu, Linux musl (pure and vendored OpenSSL),
macOS and Windows now enable the quic feature. The transport stays an
opt-in quic:// operand and the feature is not a default. On Windows
only the client applies: the daemon refuses quic directives. FreeBSD
is not built by this workflow.

A new non-required linux-musl-quic job builds the static musl binary
with quic, since the musl release tarballs now depend on it.
The two mutual-TLS client flags were the only QUIC options missing from
--help and from the OC_EXTENSION_FLAGS registry, so surface_diff kept
them as accepted exceptions. Both now render under the QUIC heading,
the registry carries every --quic* flag, and the stale accepted
entries are gone. The extension env reference gains OC_RSYNC_QUIC_CC
and OC_RSYNC_QUIC_WINDOW.
A disk error raised before a file's Commit (backup, writer setup,
append-verify prefix read, or a chunk write) returned without consuming
the rest of that file's queued messages. The disk thread then answered
each leftover chunk with a separate error result, filled the bounded
result queue and blocked, while the network thread blocked sending the
next chunk. The transfer stalled until the peer's idle timeout, which is
the intermittent QUIC push stall.

Route every pre-Commit error exit through the existing open-failure
drain, mirroring upstream discard_receive_data() (receiver.c:1254-1261).
Mint every certificate shape with rcgen at test time and drive the real
daemon and client over loopback, pull and push, pinning the exit code
and a stable stderr fragment per row: accepted chains (DNS and IP SANs,
an intermediate, P-256/P-384/Ed25519/RSA-2048 keys), refused server
leaves (CA:TRUE, SAN mismatch, missing serverAuth, expired, not yet
valid, unknown issuer), daemon identity load failures, client trust
file errors and the mutual TLS cases.

Run the matrix in the linux-quic job and make docs/quic-transport.md
state the same rules, naming the test as their source of truth.
… files

Expired and not-yet-valid certificates in the validation matrix now
take windows relative to the current time instead of fixed years. A new
lint step fails when a key or certificate file, a PEM block with a body,
or a base64 DER blob is checked in. The only allowance is the short
malformed-key parse-error input in rsync_io quic/trust.rs, named by exact
path; a real-length body is reported even there.
A test helper named serve made the name-based dead-code census treat the
unused async_session listener serve() as referenced.
@oferchen
oferchen force-pushed the refactor/bwlimit-sleep-like-upstream branch from 04a6ec7 to b0e0e72 Compare October 21, 2026 03:46
@oferchen oferchen changed the title refactor: sleep --bwlimit with nanosleep like upstream, make timing tests deterministic fix: QUIC in the default build with Retry under load, bwlimit sleep like upstream Oct 21, 2026
@github-actions github-actions Bot added bug Something isn't working and removed refactor labels Oct 21, 2026
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