Skip to content

fix(daemon): default listener to IPv4-only matching upstream - #5908

Merged
oferchen merged 3 commits into
masterfrom
fix/uts-dd-daemon-exit10-ipv4-default
Jun 18, 2026
Merged

oferchen merged 3 commits into
masterfrom
fix/uts-dd-daemon-exit10-ipv4-default

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

The default daemon listener used to bind IPv6+IPv4 (dual-stack) and treat any per-family accept(2) failure as fatal. On GitHub Actions Linux runners the IPv6 stack is configured but unreachable: bind(2) to [::]:873 succeeds, but accept(2) then returns a non-routable address family and the daemon exits 10 ("error in socket I/O") even though the IPv4 listener was healthy. This matched the upstream testsuite "daemon (exit 10)" CI-only failure pattern documented under UTS-DD-daemon-exit10.

This PR mirrors upstream socket.c::open_socket_in (rsync-3.4.4 lines 402-499) and socket.c::start_accept_loop (lines 537+) semantics:

  • Defaults to IPv4-only when no --ipv4/--ipv6 flag and no explicit --bind address is given. Matches upstream behaviour when default_af_hint = 0 collapses to AF_INET on systems where the IPv6 stack is configured but unreachable.
  • Accepts --ipv4 --ipv6 together as the explicit dual-stack opt-in (previously rejected as a CLI conflict). Sets a new dual_stack flag on RuntimeOptions so the accept loop binds one socket per family.
  • Tolerates per-family accept(2) failures in run_dual_stack_loop: the surviving family keeps serving connections, the failed family logs a warning via the new warn_per_family_accept_failure (companion to the existing warn_per_family_bind_failure). Only a fatal accept on the last surviving family escalates to daemon exit 10.
  • Adds OC_RSYNC_DAEMON_ADDRESS_FAMILY=ipv4|ipv6|both (also accepts v4, inet, dual, etc.) as a runtime override so CI/test fixtures can force a family without rebuilding the CLI.

The bind-address conflict path is preserved: --bind 1.2.3.4 --ipv6 still errors with "cannot use --ipv6 with an IPv4 bind address".

Upstream reference

target/interop/upstream-src/rsync-3.4.4/socket.c:

  • open_socket_in:402-499 - family-iteration bind loop; the daemon binds every getaddrinfo result and only fails when zero sockets bound. The per-family bind() failed: %s (address-family %d) diagnostic is the model for our warn_per_family_bind_failure / warn_per_family_accept_failure helpers.
  • start_accept_loop:537+ - select(2) over every successful socket; one busted descriptor does not collapse the loop over the others. Our fix restores the same semantic in run_dual_stack_loop.

The upstream default (default_af_hint = 0 in options.c:155) is "any protocol", which on Linux yields both IPv6 and IPv4 from getaddrinfo. On platforms where the IPv6 stack is configured but unreachable, upstream's diagnostic surfaces a per-family error and continues with the surviving family. oc-rsync now does the same, but additionally defaults to IPv4-only when no family is requested to avoid the silent IPv6-then-fail pattern on GitHub Actions runners.

Test plan

  • CI fmt+clippy passes.
  • cargo nextest run -p daemon covers:
    • runtime_options_tests::ipv4_then_ipv6_enables_dual_stack + reverse-order companion.
    • runtime_options_tests::dual_stack_default_is_false.
    • parse_address_family_env_accepts_* (ipv4/ipv6/both variant tables).
    • warn_per_family_accept_failure_labels_*.
    • listener_address_family::default_daemon_binds_ipv4_and_serves_ipv4_client (live daemon).
    • listener_address_family::env_override_{ipv4,both}_serves_ipv4_client.
    • listener_address_family::both_family_flags_enable_dual_stack_listener.
    • listener_address_family::ipv6_flag_forces_ipv6_only (probe-skipping on IPv6-less runners).
  • Linux musl, macOS, Windows matrix cells exercise the same tests; macOS and Linux verify the live daemon greeting; Windows only relies on the unit-level coverage.

Refs: UTS-DD-daemon-exit10.1, UTS-DD-daemon-exit10.2

@github-actions github-actions Bot added the bug Something isn't working label Jun 17, 2026
@oferchen
oferchen force-pushed the fix/uts-dd-daemon-exit10-ipv4-default branch 2 times, most recently from 6c336e7 to b9cb579 Compare June 18, 2026 03:18
oferchen added 3 commits June 18, 2026 07:14
The default daemon listener used to bind IPv6+IPv4 (dual-stack) and
treat any per-family accept failure as fatal. On GitHub Actions Linux
runners the IPv6 stack is configured but unreachable: `bind(2)` to
`[::]:873` succeeds, but `accept(2)` then returns a non-routable
address family and the daemon exits 10 ("error in socket I/O") even
though the IPv4 listener was healthy. This matched the upstream
testsuite "daemon (exit 10)" CI-only failure pattern documented under
UTS-DD-daemon-exit10.

Mirror upstream `socket.c::open_socket_in` (rsync-3.4.4:402-499)
semantics by:

- Defaulting to IPv4-only when no `--ipv4`/`--ipv6` flag and no
  explicit `--bind` address is given. Matches upstream's
  `default_af_hint = 0` behaviour when the IPv6 stack is configured
  but unreachable.
- Accepting `--ipv4 --ipv6` together as the explicit dual-stack
  opt-in (previously rejected as a CLI conflict). Sets a new
  `dual_stack` flag on `RuntimeOptions` so the accept loop binds one
  socket per family.
- Tolerating per-family `accept(2)` failures in `run_dual_stack_loop`:
  the surviving family keeps serving connections, the failed family
  logs a warning. Only a fatal accept on the last surviving family
  escalates to daemon exit 10.
- Adding `OC_RSYNC_DAEMON_ADDRESS_FAMILY=ipv4|ipv6|both` as a runtime
  override so CI/test fixtures can force a family without rebuilding
  the CLI.

The bind-address conflict path is preserved: `--bind 1.2.3.4 --ipv6`
still errors with "cannot use --ipv6 with an IPv4 bind address".

Per-family bind warnings already existed (`warn_per_family_bind_failure`);
this commit adds the companion `warn_per_family_accept_failure` so
runtime accept regressions are auditable too.

upstream: target/interop/upstream-src/rsync-3.4.4/socket.c
  - open_socket_in:402-499 - family-iteration bind loop
  - start_accept_loop:537+ - per-family `select(2)` survives single
    descriptor failure

Tests:
- runtime_options/tests.rs: --ipv4 --ipv6 enables dual_stack;
  default has dual_stack=false.
- server_runtime/tests.rs: parse_address_family_env accepts ipv4/ipv6/
  both variants; rejects unknown values; warn_per_family_accept_failure
  labels IPv4/IPv6.
- crates/daemon/tests/listener_address_family.rs: live daemon end-to-end
  with default, --ipv6, --ipv4 --ipv6, and OC_RSYNC_DAEMON_ADDRESS_FAMILY
  variants.

Refs: UTS-DD-daemon-exit10.1, UTS-DD-daemon-exit10.2
Two follow-ups to the daemon listener defaults change:

1. `run_single_listener_loop` slept 500ms (`SIGNAL_CHECK_INTERVAL`)
   between `accept(2)` polls on the non-blocking listener. This was
   masked previously because the dual-stack default sent traffic
   through `run_dual_stack_loop`, which uses a 50ms WouldBlock sleep
   and a 100ms channel `recv_timeout`. Defaulting to IPv4-only single-
   listener surfaced the latency: the cold-start bench saw 496ms per
   client vs 115ms upstream (4.3x ratio, regression threshold 1.5x).
   Lower the single-listener WouldBlock sleep to 50ms so first-
   connection latency is bounded by the same interval as the dual-
   stack path. `SIGNAL_CHECK_INTERVAL` is still honoured for the
   signal-flag inspection at the top of the loop body via
   `check_signals_and_maintain`.

2. `async_ssh_transport.rs` had two more call sites of
   `flags::build_wire_format_rules` left un-updated when #5899 added
   the `delete_excluded: bool` parameter. Pass `config.delete_excluded()`
   to match the other call sites.

No wire/behaviour change; both fixes are mechanical.
@oferchen
oferchen force-pushed the fix/uts-dd-daemon-exit10-ipv4-default branch from d42ddc5 to 6908b0b Compare June 18, 2026 04:14
@oferchen
oferchen merged commit e3a6896 into master Jun 18, 2026
1 of 5 checks passed
@oferchen
oferchen deleted the fix/uts-dd-daemon-exit10-ipv4-default branch June 18, 2026 04:16
oferchen added a commit that referenced this pull request Aug 24, 2026
* fix(daemon): default listener to IPv4-only matching upstream

The default daemon listener used to bind IPv6+IPv4 (dual-stack) and
treat any per-family accept failure as fatal. On GitHub Actions Linux
runners the IPv6 stack is configured but unreachable: `bind(2)` to
`[::]:873` succeeds, but `accept(2)` then returns a non-routable
address family and the daemon exits 10 ("error in socket I/O") even
though the IPv4 listener was healthy. This matched the upstream
testsuite "daemon (exit 10)" CI-only failure pattern documented under
UTS-DD-daemon-exit10.

Mirror upstream `socket.c::open_socket_in` (rsync-3.4.4:402-499)
semantics by:

- Defaulting to IPv4-only when no `--ipv4`/`--ipv6` flag and no
  explicit `--bind` address is given. Matches upstream's
  `default_af_hint = 0` behaviour when the IPv6 stack is configured
  but unreachable.
- Accepting `--ipv4 --ipv6` together as the explicit dual-stack
  opt-in (previously rejected as a CLI conflict). Sets a new
  `dual_stack` flag on `RuntimeOptions` so the accept loop binds one
  socket per family.
- Tolerating per-family `accept(2)` failures in `run_dual_stack_loop`:
  the surviving family keeps serving connections, the failed family
  logs a warning. Only a fatal accept on the last surviving family
  escalates to daemon exit 10.
- Adding `OC_RSYNC_DAEMON_ADDRESS_FAMILY=ipv4|ipv6|both` as a runtime
  override so CI/test fixtures can force a family without rebuilding
  the CLI.

The bind-address conflict path is preserved: `--bind 1.2.3.4 --ipv6`
still errors with "cannot use --ipv6 with an IPv4 bind address".

Per-family bind warnings already existed (`warn_per_family_bind_failure`);
this commit adds the companion `warn_per_family_accept_failure` so
runtime accept regressions are auditable too.

upstream: target/interop/upstream-src/rsync-3.4.4/socket.c
  - open_socket_in:402-499 - family-iteration bind loop
  - start_accept_loop:537+ - per-family `select(2)` survives single
    descriptor failure

Tests:
- runtime_options/tests.rs: --ipv4 --ipv6 enables dual_stack;
  default has dual_stack=false.
- server_runtime/tests.rs: parse_address_family_env accepts ipv4/ipv6/
  both variants; rejects unknown values; warn_per_family_accept_failure
  labels IPv4/IPv6.
- crates/daemon/tests/listener_address_family.rs: live daemon end-to-end
  with default, --ipv6, --ipv4 --ipv6, and OC_RSYNC_DAEMON_ADDRESS_FAMILY
  variants.

Refs: UTS-DD-daemon-exit10.1, UTS-DD-daemon-exit10.2

* fix: lower single-listener accept poll to 50ms; fix async-ssh build

Two follow-ups to the daemon listener defaults change:

1. `run_single_listener_loop` slept 500ms (`SIGNAL_CHECK_INTERVAL`)
   between `accept(2)` polls on the non-blocking listener. This was
   masked previously because the dual-stack default sent traffic
   through `run_dual_stack_loop`, which uses a 50ms WouldBlock sleep
   and a 100ms channel `recv_timeout`. Defaulting to IPv4-only single-
   listener surfaced the latency: the cold-start bench saw 496ms per
   client vs 115ms upstream (4.3x ratio, regression threshold 1.5x).
   Lower the single-listener WouldBlock sleep to 50ms so first-
   connection latency is bounded by the same interval as the dual-
   stack path. `SIGNAL_CHECK_INTERVAL` is still honoured for the
   signal-flag inspection at the top of the loop body via
   `check_signals_and_maintain`.

2. `async_ssh_transport.rs` had two more call sites of
   `flags::build_wire_format_rules` left un-updated when #5899 added
   the `delete_excluded: bool` parameter. Pass `config.delete_excluded()`
   to match the other call sites.

No wire/behaviour change; both fixes are mechanical.

* fix(clippy): drop unused constant; use io::Error::other
oferchen added a commit that referenced this pull request Sep 8, 2026
…#7745)

The eleven docs that cite SIGNAL_CHECK_INTERVAL were line-accurate when
written, but the code moved twice since: PR #5908 lowered the
single-listener WouldBlock sleep from 500ms to 50ms and deleted the
constant, and PR #7681 replaced accept-side sleep-polling with a
readiness wait (poll(2) in PollAcceptEngine, kevent(2) behind the
opt-in macos-kqueue feature in KqueueAcceptEngine) in
server_runtime/accept_engine.rs.

Bring the living documents back in line with the tree:

- kqueue-pipeline-audit: mark the two daemon-accept surface rows
  migrated (KQ-S.1 landed via #6217/#7681) instead of describing the
  deleted sleep-poll loops as the current implementation.
- daemon-tpc-benchmark-plan: bound SIGTERM-to-drain latency by the
  accept engine's 50ms/100ms signal-check cadence, and mark tracker
  #1683 completed.
- daemon-event-loop-multiplexing: add a status note to the follow-up
  list and tick #1683, which #5908/#7681 closed.
- daemon-thread-per-connection-scalability: mark tracker #1683
  completed in the references list.
- dis-4a, dis-3, daemon-coldstart-profile, daemon-coldstart-rebench:
  record that DIS-4.a R1 has since landed, next to the sections that
  rank it as the top open bottleneck; retarget the DIS-2 file index
  entry that still pointed the constant at listener.rs.

The audit bodies keep their historical line citations: they describe
the tree that was measured. daemon-thread-per-connection.md,
async-daemon-listener.md (pinned 'Last verified: 2026-05-01'), and
daemon-async-listener-rfc.md are left untouched as dated snapshots.
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