Repository navigation
fix: treat IPv6 enumeration errors as errors, not absence - #128
Conversation
Codecov Report❌ Patch coverage is
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
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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_inhelper so enumeration failures become hard errors rather than being folded into “no address”. - Change
pick_default_interface_indexto returnio::Result<Option<u32>>and propagate enumeration/read failures instead of collapsing them intoNone. - 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.
| 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) | ||
| }) | ||
| }; |
| 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 |
| assert!( | ||
| has_addr_in(&iface, Family::V6).is_ok(), | ||
| "the guard must disarm the injection" | ||
| ); |
| assert!( | ||
| has_addr_in(&iface, Family::V6).is_ok(), | ||
| "the guard must disarm the injection" | ||
| ); |
al8n
left a comment
There was a problem hiding this comment.
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
fmtis yours — three spots,cargo fmtfixes it.locis ours, not yours. It fails withInput required and not supplied: github-tokenbecause 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
367c32c to
dffb166
Compare
|
Thanks for the detailed review and guidance @al8n! I've updated the PR accordingly:
|
al8n
left a comment
There was a problem hiding this comment.
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 isio::Resultvsstd::io::Result, a path spelling.tier_base— identical.- The picker now feeds
rank_candidatesrather than re-probing in four passes, and my R1 scenario (A has v4/no v6, B has no v4 and anEINTRon 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.
Description
Fixes #103.
getifsaddress enumeration can fail withEINTRwhen DHCP, VPN, or interface churn interrupts a dump.hick-compioandhick-reactortreated thatErras "this interface has no IPv6" by folding it intofalse. That is a negative claim the evidence does not support: the same confusionhick-mio'shas_addr_inwas 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.rsandhick-reactor/src/endpoint.rs: port thehas_addr_inthree-state rule into bind andpick_default_interface_index.Err, not as a missing address.Verification
cargo test -p hick-compio --lib endpointcargo test -p hick-reactor --lib endpoint