Repository navigation
feat(network): prefer IPv6 with a bounded IPv4 fallback - #1320
Conversation
# Conflicts: # rust-modules/screens/src/family.rs # rust-modules/screens/src/preferences.rs # rust-modules/screens/src/preferences/picker.rs
|
A family picker is useful, and the strict modes look well plumbed. My concern is with making IPv6 preferred the default. A lot of home networks have IPv6 on the LAN without a working public IPv6 path (CGNAT or IPv4-only fibre), so I read through how the fallback behaves at What already limits the damage
What the new default costs
No mode reproduces today's behaviour
Suggestion Add a fourth mode, IPv4 preferred (IPv6 fallback), that matches |
# Conflicts: # rust-modules/screens/src/preferences.rs # rust-modules/screens/src/preferences/picker_tests.rs
|
Thanks @fraygox — good catch, particularly the grace-window behavior and the fact that the original three choices couldn't reproduce I've updated this PR to follow your suggestion:
Checks passed: 19 preference tests, 27 Plex probe tests, cargo test-target type checks, localization, dependency gates and the no-default-features build check. Physical LG/webOS playback/network testing is still outstanding (the host UI unit test executable cannot link here without SDL2/SDL2_ttf/GL dev libraries). Appreciate the careful review! |
GLinnik21
left a comment
There was a problem hiding this comment.
Thanks for this, and thanks @fraygox for the careful read.
I'd rather not ship a picker for this. Most people won't know what IPv4 vs IPv6 means on a TV, and the strict modes can quietly break the app. "IPv6 only" applies to the live connection right away, so on an IPv4 server, browsing and playback stop until a restart.
I'm actually pro IPv6 and would like the app to prefer it by default, with no setting. Something like Happy Eyeballs (prefer IPv6, fall back to IPv4 after a short delay) in the route race:
- rank IPv6 ahead of its IPv4 twin within the same location/scheme tier
- when IPv4 has already answered and the only better candidate left is the IPv6 twin, wait ~250 ms instead of the full 1.5 s grace
- log which family won and how long each took, so there's data behind the default
That way working IPv6 wins, broken IPv6 costs a quarter second, and nobody has to find a setting.
Would you be up for re-scoping the PR that way? Your probe changes are most of the way there. It should take the IP mode as an argument rather than reading the session global, and the legacy prefer_ipv6/ipv6_only keys can go, since no release ever wrote them. A TV run on a dual-stack network would also help a lot before it lands.
| /// field's own doc and `auth.rs`'s race semantics for what that answer is allowed to mean. | ||
| pub fn candidates(res: &Resource, policy: CredentialPolicy) -> Vec<Candidate> { | ||
| // Pure cached read, not a storage I/O request. It is already populated at boot. | ||
| let saved = super::session::peek(); |
There was a problem hiding this comment.
planner shouldn't read the session global. can the ip mode come in as an argument? candidates_with_ip_mode already takes one
| } | ||
| }) { | ||
| let location = tier(c); | ||
| let ipv6 = c.ipv6 || c.address.contains(':'); |
There was a problem hiding this comment.
nit: v6 check is computed twice here and a few lines up in the filter. compute once so the filter and sort can't disagree
| c.address, "192.168.0.10", | ||
| "IPv4 leads the plaintext fallbacks" | ||
| c.address, "2001:db8::1", | ||
| "IPv6 leads the plaintext fallbacks by default" |
There was a problem hiding this comment.
these expect IPv6 first but the default mode is IPv4 first. passes only if another test left an IPv6 session behind?
| fn ip_family_modes_constrain_plain_http_literal_resolution() { | ||
| use crate::net::{IpFamily, set_ip_family}; | ||
| let _guard = plx_base::testlock::serial(); | ||
| set_ip_family(IpFamily::V4); |
There was a problem hiding this comment.
this flips the global IP family while other tests run in parallel, and a failing assert skips the reset. could the family be passed in instead?
Replace the opt-in family picker with automatic dual-stack discovery. Rank IPv6 ahead of IPv4 within a location/security tier; keep IPv4 eligible and limit same-tier IPv6 grace to 250 ms after IPv4 answers. Log each probe family/latency and the selected family, without global IP family configuration or legacy preference keys. Add regression tests for fast, slow and blackholed IPv6 paths.
|
Thanks @GLinnik21 — I've re-scoped #1320 as requested and pushed the updated branch.
Verification after merging current
Still outstanding: physical LG/webOS validation on a real dual-stack and broken-IPv6 network; this environment does not have a TV configured, so I haven't claimed hardware/playback testing. I re-read the diff against current |
|
Thanks for the re-scope, @valentinBoch. The picker, the strict modes, the global state and the legacy keys are all gone, IPv6 ranks first within a tier, and the logging is in. Reviewed at The 250 ms window works for one IPv4 route and its IPv6 twin. Two other cases still behave differently, and neither has a test. 1. A dead IPv6 address can still hold the race for 1.5 s (
|
| Situation | Expected |
|---|---|
| Local v4 answers, Local v6 hangs | v4 accepted at +250 ms |
| Local v6 answers 100 ms after Local v4 | v6 wins |
[v6a dead, v6b ok, v4 ok] in one tier |
settles when v6b answers, with no wait for v6a |
| Away from home: Remote v4 answers, Local hangs | Remote v4 accepted at 1.5 s (as on main) |
| …and Remote v6 answers 1.2 s later | Remote v4 kept |
| Remote v4 answers, Local v4 at 800 ms | Local v4 wins; Local v6 gets 250 ms from 800 ms |
| Relay only | same rules inside the relay phase |
On the third row: two same-family addresses of the same rank already cost 1.5 s on main for IPv4 (could_outrank: score == best.score && index < best.index). Covering that here is optional, but this PR makes it common for IPv6.
Tests
Per AGENTS.md, please add the regressions first and see them fail on the current head. The table rows map well onto the pure grace_for_pending / race_decided tests, as the one at :421 already does, with fixed timings and no threads. The threaded "IPv6 wins inside the quarter second" test (auth_discovery_tests.rs:388-401) has about 160 ms of slack and asserts an exact order, so it is likely to flake when two make check runs share a machine.
Minor
- Logging:
auth: '{name}' probe timed out at {address}:{port}becameprobe family=IPv6 result=timeout waited_ms=N. With up to eight direct routes per server, the log can no longer say which route timed out. Please keep the server, tier, scheme and address, and add family and latency to that line. The new line also logsresult=unreachable, against the comment atauth.rs:2192("Not logged here"). - Docs:
rust-modules/plex/src/plex/CLAUDE.md:304-307should describe the window as starting from the IPv4 twin's answer once that is fixed. - CI and device: CI has not run on
e021420ayet. A TV run on a dual-stack network is still wanted before this lands, ideally including one with IPv6 silently dropped.
Generated by Claude Code
Evaluate each pending route's win window separately rather than a shared race grace. Higher-scored/better-tier routes retain 1.5s from first reply; equivalent IPv6 candidates get 250ms from the current IPv4 winner's reply. Never promote late IPv6 or wait for same-family ties. Preserve per-address timeout diagnostics, remove duplicate unreachable logs, use deterministic no-thread regression tests, and update discovery documentation.
|
Thanks @GLinnik21 — I followed up on your review and pushed I followed the requested red → green workflow on the previous PR head ( The new decision logic is per candidate:
Other requested changes:
Checks on the corrected tree: The full host UI executable test suite still cannot link on this server without SDL2/SDL2_ttf/GL development libraries; I am not claiming a full Thanks again for the detailed scenarios and specific feedback. |
|
Thanks @valentinBoch, the per-route rule in TV verification at
|
| Case | Selected | IPv4 answer → selected |
|---|---|---|
| C0: no IPv6 route | IPv4 | +0 ms |
| C1: IPv6 twin answers +100 ms | IPv6 (latency_ms=115) |
chosen as soon as IPv6 answered |
| C2: IPv6 twin accepts, never answers (2 runs) | IPv4 | +246 / +247 ms (probe not waited for … family=IPv6 waited_ms≈260) |
| C3: IPv6 twin answers +400 ms | IPv4 | +246 ms; the late IPv6 reply was ignored |
| C4: SYN silently dropped (stealth firewall) | IPv4 | +246 ms |
| C4′: IPv6 refused at once (RST) | IPv4 | +0 ms |
| C5: dead IPv6 listed first, live IPv6 at +100 ms, plus IPv4 | IPv6 | settled on the live IPv6 answer, with no wait for the dead one |
Playback in C2 worked over IPv4 (direct play). The held IPv6 proxy saw no connection after the race.
make check (0 failed) and make check-nodef both pass, and all 13 CI checks on 00dbf91 are green.
Not covered: a real ISP dual-stack path. These runs were LAN-only, with the mock standing in for the server.
Optional follow-ups (not blocking)
auth/ports.rs:333-384: the time left in the window is computed from two clock reads per loop. If the window closes between them, the race can fall through to the 5 s / 10 s probe deadline. Computing it once per iteration fixes this.mainalready has the same pattern.auth_discovery_tests.rs:384,:413: these two threaded wall-clock tests are the only ones that exercise the real wake-up, and they have 350–500 ms of slack. Widen them, or switch to event-ordered channels.auth.rs:2139-2143: 401, wrong-server and plaintext-only answers now log two lines each.- Stale comments:
screens/src/login.rs:118-119("at mostgrace(1.5 s)") and theprobe_server_racingdoc comment.
Generated by Claude Code
|
Thanks! |
Summary
Prefer IPv6 automatically, with IPv4 as a fast fallback, during Plex server discovery. There is no user-facing IP-family picker, no strict mode, and no change to ordinary app-managed network transport policy.
This re-scopes the PR in response to GLinnik21's review.
How it works
prefer_ipv6/ipv6_onlypreferences are removed.Regression coverage
Verification
cargo test --lib -p plx_plex -p plx_session: 805 + 348 passed, 0 failed on the new patch; 7/7 fixed-clock review tests passed.git diff --check,ci/check-deps.shandmake lint: passed.cargo check --tests -p plxnative-modules -p plx_screens: passed (type-checks host application / screen test targets without linking native libraries).make checkagainst the updated upstreammain: blocked at host linking because the Linux environment lacks-lSDL2,-lSDL2_ttfand-lGL; this is not reported as a passing suite. The Python branch was stopped after the Cargo branch failed.The latest corrective commit modifies only the discovery race, its unit tests and developer documentation. The PR as a whole retains its IPv6-first candidate planner.