fix(desktop): select the WSL route source address #5889
main fromrefs/pull/5889/head·opened View on GitHubWhat Changed#
- Resolve the selected WSL distro's preferred IPv4 source with
ip -4 route get 1.1.1.1instead of assuming the firsthostname -Iaddress is reachable. - Parse the exact
srctoken with strict IPv4 octet validation. - Fall back to
hostname -Ionly when it yields exactly one valid IPv4 address; ambiguous Docker-bridge output now returns no address rather than guessing. - Keep the existing total timeout, scoped process cleanup, NAT direct-address behavior, and mirrored-mode loopback mapping.
- Add command-level and parser regression coverage for the reported Docker ordering, missing route source, unavailable
ip, invalid octets, ambiguous fallback, and timeout behavior.
Why#
hostname -I enumerates addresses from every interface without a stable reachability order. With Docker running inside a mirrored WSL distro, bridge addresses can precede the route-selected host address, causing the desktop to poll an unreachable bridge indefinitely.
Asking the kernel for its preferred route source avoids interface-order assumptions without hardcoding Docker or RFC1918 ranges.
Closes #5211.
Validation#
vp test run apps/desktop/src/wsl/DesktopWslEnvironment.test.ts— 38 passedvp test run apps/desktop/src/backend/DesktopBackendConfiguration.test.ts -t "resolveWsl preserves existing WSLENV entries when forwarding backend secrets"— 1 passedvp run --filter @t3tools/desktop typecheckvp lint apps/desktop/src/wsl/DesktopWslEnvironment.ts apps/desktop/src/wsl/DesktopWslEnvironment.test.ts --report-unused-disable-directivesvp fmt --check apps/desktop/src/wsl/DesktopWslEnvironment.ts apps/desktop/src/wsl/DesktopWslEnvironment.test.tsgit diff --check origin/main...HEAD- Local Ubuntu 24.04 route lookup returned
src 172.20.42.37, matching the parser contract.
The local manual check used default WSL NAT. The reporter's exact mirrored-networking-plus-in-distro-Docker topology remains the external acceptance boundary.
Checklist#
- This PR is small and focused
- I explained what changed and why
- No UI, animation, or interaction changes
Note
Fix getDistroIpImpl to select the WSL route source address instead of hostname#
getDistroIpImplnow runsip -4 route get 1.1.1.1first and extracts thesrcfield via the newparseWslRouteSourcehelper, falling back tohostname -Ionly when the route command fails or returns a non-zero exit code.parseSingleWslHostnameAddressreplaces the previous loose regex, accepting the fallback only whenhostname -Ireturns exactly one valid IPv4 address.- IPv4 validation is now done via
isIpv4Address(checks each octet ≤255) instead of a regex pattern. - The timeout constant switches from
USER_HOME_TIMEOUTtoDISTRO_IP_TIMEOUT(5 seconds). - Behavioral Change: previously the first IPv4-like token from
hostname -Iwas accepted; now multiple addresses fromhostname -Iyieldnone, and non-zero exit codes or spawn errors also yieldnone.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
Verified on Windows 11, Node 24: 38/38 pass on this branch. Reverting only
DesktopWslEnvironment.tsto main while keeping the new tests fails 10 of them, including "uses the route-selected src instead of the first hostname address" and "uses one total timeout and does not start the fallback after it expires", so the suite covers the regression rather than the current behavior.This is unit-level only. I did not run the packaged app against a real WSL distro, so I can't confirm the end-to-end Docker-bridge case from #5211.
Re-verified on Ubuntu WSL (this machine, 2026-08-15).
DesktopWslEnvironment.test.ts: 38/38 on the PR. Replacing the source withorigin/mainfails 10/38 — allis not a function, becausegetDistroIpImpl/parseWslRouteSource/parseSingleWslHostnameAddressdo not exist on main. That proves the tests are new. It does not prove they catch a wrong-address pick in the oldhostname -Ipath.Live on this distro the two answers agree:
ip -4 route get 1.1.1.1 → src 172.25.119.119 hostname -I → 172.25.119.119Only one address, so the Docker-bridge ordering bug does not reproduce here (Docker Desktop is a separate distro). The parser tests still look right: exact
srctoken, rejectprefsrc, reject a multi-address fallback.The fallback-to-none when
hostname -Iis ambiguous is the part I would keep even if the route lookup stays.Previous unit pass on 8/10 still holds.
Note
🤖 GPT-6 Astra (preview) responding on behalf of Theo
This was closed as part of an automated cleanup pass. If you believe it was closed in error, reply here and we will get it reopened.
Closing in favor of #8438. It compares WSL address candidates with Windows interfaces, which avoids accepting an Internet route source that belongs to an unreachable WSL VPN. Review continues there. This branch's strict IPv4 parsing, single-address fallback, and shared timeout cases are recorded on the retained PR, which still needs native topology verification.
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
a6bc3b3a-9fa4-4461-8270-3a25fa5270acYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share