Skip to content

fix: treat IPv6 enumeration errors as errors, not absence - #128

Merged
al8n merged 1 commit into
al8n:mainfrom
myukitty:fix/ipv6-enum-error-not-absence
Aug 15, 2026
Merged

al8n merged 1 commit into
al8n:mainfrom
myukitty:fix/ipv6-enum-error-not-absence

Conversation

@myukitty

Copy link
Copy Markdown
Contributor

Description

Fixes #103.

getifs address enumeration can fail with EINTR when DHCP, VPN, or interface churn interrupts a dump. hick-compio and hick-reactor treated that Err as "this interface has no IPv6" by folding it into false. That is a negative claim the evidence does not support: the same confusion hick-mio's has_addr_in was rebuilt to prohibit.

Ok(empty) still degrades a requested family so dual-stack binds work on IPv4-only hosts. A failed read now fails the bind or default-interface picker instead of ranking the wrong link.

Changes

  • hick-compio/src/endpoint.rs and hick-reactor/src/endpoint.rs: port the has_addr_in three-state rule into bind and pick_default_interface_index.
  • Matching unit tests inject an enumeration failure and assert it is reported as Err, not as a missing address.

Verification

  • cargo test -p hick-compio --lib endpoint
  • cargo test -p hick-reactor --lib endpoint

@codecov

codecov Bot commented Aug 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.59788% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.49%. Comparing base (a1b486b) to head (dffb166).

Files with missing lines Patch % Lines
hick-compio/src/endpoint.rs 81.91% 17 Missing ⚠️
hick-reactor/src/endpoint.rs 85.26% 14 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #128      +/-   ##
==========================================
- Coverage   92.50%   92.49%   -0.02%     
==========================================
  Files          94       94              
  Lines       17311    17412     +101     
==========================================
+ Hits        16014    16105      +91     
- Misses       1297     1307      +10     
Files with missing lines Coverage Δ
hick-reactor/src/endpoint.rs 82.37% <85.26%> (+1.02%) ⬆️
hick-compio/src/endpoint.rs 82.43% <81.91%> (+2.43%) ⬆️

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a1b486b...dffb166. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aligns hick-compio and hick-reactor with the three-state address-enumeration rule used elsewhere in the project: an address enumeration Err is now treated as an error (and surfaced), while Ok(empty) continues to mean “no addresses for this family” and can still trigger graceful dual-stack degradation. This prevents incorrect “IPv6 absent” conclusions when getifs enumeration is interrupted (e.g., EINTR).

Changes:

  • Update bind-family selection to use a has_addr_in helper so enumeration failures become hard errors rather than being folded into “no address”.
  • Change pick_default_interface_index to return io::Result<Option<u32>> and propagate enumeration/read failures instead of collapsing them into None.
  • Add unit tests that inject address-enumeration failures and assert the error is surfaced (not treated as missing IPv6).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
hick-reactor/src/endpoint.rs Propagates interface/address enumeration errors via io::Result, adds has_addr_in, and adjusts bind-family selection accordingly.
hick-reactor/src/endpoint/tests.rs Adds tests to ensure forced enumeration failures surface as errors (not absence).
hick-compio/src/endpoint.rs Mirrors the reactor changes: propagate enumeration errors, add has_addr_in, and update bind-family selection.
hick-compio/src/endpoint/tests.rs Adds equivalent failure-injection tests for compio’s endpoint picker and has_addr_in.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread hick-reactor/src/endpoint.rs Outdated
Comment on lines +343 to +359
let matches_families = |i: &getifs::Interface, strict: bool| -> std::io::Result<bool> {
let has_v4 = if want_v4 {
has_addr_in(i, Family::V4)?
} else {
false
};
let has_v6 = if want_v6 {
has_addr_in(i, Family::V6)?
} else {
false
};
Ok(if strict {
(!want_v4 || has_v4) && (!want_v6 || has_v6)
} else {
(want_v4 && has_v4) || (want_v6 && has_v6)
})
};
Comment thread hick-compio/src/endpoint.rs Outdated
Comment on lines +429 to +433
let matches_families = |i: &getifs::Interface, strict: bool| -> io::Result<bool> {
let has_v4 = if want_v4 {
has_addr_in(i, Family::V4)?
} else {
false
Comment on lines +83 to +86
assert!(
has_addr_in(&iface, Family::V6).is_ok(),
"the guard must disarm the injection"
);
Comment on lines +76 to +79
assert!(
has_addr_in(&iface, Family::V6).is_ok(),
"the guard must disarm the injection"
);

@al8n al8n left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking this on — the diagnosis is exactly right, and the framing in your description ("that is a negative claim the evidence does not support") is the rule we want. getifs's own source agrees with you: it surfaces EINTR specifically so a partial-but-Ok result cannot silently drop interfaces.

Build, tests and clippy are all clean locally (hick-compio 120, hick-reactor 111, -D warnings clean). One blocking issue, and it comes from the port being half of what hick-mio does.

Blocking: the picker probes candidates whose answer cannot change the result, and dies on their transient error

matches_families probes both requested families for every candidate, with ? propagating, and it runs for every candidate in every tier pass.

Concrete regression, dual-stack request, two UP multicast non-loopback candidates in order:

candidate IPv4 IPv6
A present absent
B absent enumeration returns EINTR

In the strict pass, A fails (no v6). Then B is probed: has_v4 → false, has_v6 → EINTR → ? → pick_default_interface_index returns Err, and Endpoint::server creates no endpoint at all.

But B had already lost. With no IPv4 it can at best tie A, so its IPv6 result — success, failure, or otherwise — cannot change which index is selected. Before this PR, the loose pass selected A and the endpoint came up. After it, a transient interrupted dump on an irrelevant interface prevents startup.

That is a worse failure than the one being fixed: the old bug lost IPv6 silently, this loses everything loudly, and it is reachable during an ordinary DHCP renewal or VPN transition.

hick-mio already solves this, and its comment describes your PR almost exactly:

A family is probed only while its answer could still change the winner. … a candidate already out of reach of that cannot alter the pick whatever its remaining addresses turn out to be — and a failure to read them is exactly as uninformative.

A candidate that COULD still outrank the incumbent is probed, and its failure still propagates. That is the half a fix in this direction gets backwards.

You ported the error-propagation half. The missing half is the relevance gate: track the incumbent's tier and skip any probe that cannot beat it. rank_candidates in hick-mio/src/socket.rs is one pass with an incumbent, rather than four passes that re-probe.

Please also centralise rather than copy

After this PR has_addr_in exists in three crates — hick-mio/src/socket.rs, and now hick-compio and hick-reactor. This repo has been bitten repeatedly by one rule stated in several places and kept in sync by care rather than by a compiler; the bug you are fixing is an instance of that.

hick-udp already exports Family and all three drivers depend on it, so it is the natural home for both has_addr_in and the ranking function. Moving rank_candidates there and calling it from all three would fix this class rather than one instance, and would delete code overall.

Happy to take that as a follow-up if you would rather keep this PR small — but then please use hick-mio's ranking shape here rather than the four-pass version, so the two do not disagree.

Testing

The new tests force an entire family to fail, which cannot express the case above — it needs per-candidate behaviour. Please add a deterministic test over the ranking function with the exact A/B sequence, injecting failure for one candidate's one family. That also removes the host-dependence the current tests have.

CI, and what is not your problem

  • fmt is yours — three spots, cargo fmt fixes it.
  • loc is ours, not yours. It fails with Input required and not supplied: github-token because it uploads to a gist and GitHub does not expose secrets to fork PRs. It cannot pass on any external contribution. I am fixing that separately; please ignore it.
  • codecov/* are known residuals on this repo.

Nothing else in the diff raised a concern — the Ok(empty) degradation, the Result signature change, and the caller updates all check out.

One thing worth knowing for the empty case, which you have handled correctly but which is subtler than it looks: on BSD, especially NetBSD, getifs skips an individual address whose netmask is non-canonical (a documented trade-off for point-to-point and tunnel interfaces) and returns Ok with a silently incomplete list. So Ok(empty) genuinely can mean "has an address we could not parse", and no error handling recovers it. Your choice to degrade rather than fail there is the right one.

getifs address reads can fail with EINTR during DHCP/VPN/interface
churn. Folding that Err into false made hick-compio and hick-reactor
claim an interface had no IPv6 when the dump never completed.

Port the single-pass rank_candidates and tier_base ranking algorithm from
hick-mio into hick-compio and hick-reactor so candidate addresses are probed
only while their result can outrank the incumbent, and add deterministic unit
tests covering per-candidate failure injection and incumbent ranking.

Fixes al8n#103
@myukitty
myukitty force-pushed the fix/ipv6-enum-error-not-absence branch from 367c32c to dffb166 Compare August 15, 2026 21:12
@myukitty

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review and guidance @al8n!

I've updated the PR accordingly:

  1. Single-pass
    ank_candidates with incumbent tracking
    : Ported ier_base and
    ank_candidates from hick-mio/src/socket.rs into hick-compio and hick-reactor. Candidates are evaluated in a single pass over preference tiers (0..3), and family probes are evaluated only while the candidate's reachable tier can still beat the incumbent (�est).
  2. Relevance filtering between probes: The reachable tier is re-evaluated between IPv4 and IPv6 probes. If candidate B cannot outrank incumbent A after failing IPv4, its IPv6 probe is skipped and any transient errors on irrelevant candidates will not fail the pick.
  3. Deterministic unit tests: Ported all 6 synthetic unit tests (�_failure_in_a_family_nobody_requested..., �_failure_after_an_unbeatable_candidate..., �_failure_after_the_first_probe_cost_the_strict_tier..., he_tier_a_probe_is_weighed_against..., etc.) into hick-compio/src/endpoint/tests.rs and hick-reactor/src/endpoint/tests.rs.
  4. Formatting & Lints: Ran cargo fmt and verified cargo clippy -p hick-compio -p hick-reactor -- -D warnings and all workspace unit/integration tests pass cleanly.

@al8n al8n left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good work — thank you for turning it around so quickly and so precisely.

Verified

The port is faithful. I diffed the function bodies with comments and whitespace stripped:

  • rank_candidates — logically identical across all three crates; the only difference is io::Result vs std::io::Result, a path spelling.
  • tier_base — identical.
  • The picker now feeds rank_candidates rather than re-probing in four passes, and my R1 scenario (A has v4/no v6, B has no v4 and an EINTR on v6) now selects A instead of aborting.

fmt is clean, clippy is silent at -D warnings, and the suites went 120 → 126 and 111 → 118.

The tests are better than what I asked for. Asserting on asked — which probes were performed — rather than only the result is the distinction between "the error was ignored" and "the error was never reachable", and pinning it is what stops a later refactor quietly reintroducing this. The paired "does not fail" / "still surfaces" structure is exactly right: it proves the fix did not become a swallow-everything.

One residual, and it is ours, not yours

A second review round found a narrower case that survives, and I want to be clear that it is not a defect in your port — the reviewer checked, and so did I. It exists identically in hick-mio/src/socket.rs:2691-2714 on main, which is the code I asked you to copy.

Both families requested; candidate A (v4 present, v6 absent) becomes the tier-1 incumbent; candidate B's v4 probe returns EINTR and B's v6 is absent. B cannot displace A either way — with v4 it merely ties at tier 1 and first-seen A wins; without it B serves no requested family. But the probe order is v4-then-v6, so the ? on B's v4 fires before v6 can establish that the answer was irrelevant. Probe v6 first and the same inputs succeed.

Closing it means deferring a candidate's first-probe error until the remaining family has been read far enough to decide whether it could have mattered. That is a real change to the algorithm, it belongs in all three crates at once, and it is squarely our pre-existing bug rather than something this PR introduced.

Filed as #130. Not blocking this PR — merging this strictly improves on both the previous behaviour and leaves the three drivers agreeing with each other, which is the property I care most about.

If you would like to take #130 as a follow-up you would be very welcome, but there is no expectation — you have already fixed the thing you came to fix.

Before merge

Just the fmt commit is already in, so nothing outstanding from you. loc and codecov/* remain red for the reasons in my earlier note; #129 tracks the loc one and it is not yours.

Approving.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hick-compio and hick-reactor read an enumeration error as "this interface has no IPv6"

3 participants