fix(desktop): resolve WSL distro IP from the default route, not hostname -I order #8438
ClosedSanjay-doppalapudi(GitHub profile, opens in a new tab)wants to merge 7 commits into
main fromrefs/pull/8438/headopened View on GitHubgithub-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
- apps/desktop/src/wsl/DesktopWslEnvironment.ts line 1065Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -686,3 +686,14 @@686686687687 const IPV4_PATTERN = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;688688689+const DISTRO_IP_ROUTE_PREFIX = "route:";690+const DISTRO_IP_ADDRESSES_PREFIX = "all:";691+692+// `ip -4 route get 1.1.1.1` is a pure routing-table lookup (no packet is693+// sent): its `src` field is the address the distro would use to reach an694+// external host, which is the eth0/mirrored interface Windows can reach.695+// Docker bridge interfaces never own the default route, so they cannot be696+// picked — unlike `hostname -I`, which lists them first and made the app697+// poll an unreachable 172.x bridge address forever (#5211). `hostname -I`698+// stays as the fallback for distros without a default route.699+const DISTRO_IP_SCRIPT = `printf "${DISTRO_IP_ROUTE_PREFIX}%s\\n" "$(ip -4 route get 1.1.1.1 2>/dev/null)"; printf "${DISTRO_IP_ADDRESSES_PREFIX}%s\\n" "$(hostname -I 2>/dev/null)"`;
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/desktop/src/wsl/DesktopWslEnvironment.ts lines 768 to 783OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -688,0 +763,21 @@763+ }764+ }765+ return candidates[0] ?? null;766+};767+768+const windowsIpv4Interfaces = (): ReadonlyArray<WindowsIpv4Interface> => {769+ const interfaces: WindowsIpv4Interface[] = [];770+ for (const list of Object.values(NodeOS.networkInterfaces())) {771+ if (!list) continue;772+ for (const entry of list) {773+ // Same family normalization as isLocalHostIpv4 in774+ // DesktopBackendConfiguration: Electron's Node reports the string775+ // "IPv4", some Node builds report the numeric 4.776+ const family = String(entry.family);777+ if (family === "IPv4" || family === "4") {778+ interfaces.push({ address: entry.address, netmask: entry.netmask });779+ }780+ }781+ }782+ return interfaces;783+};
- apps/desktop/src/wsl/DesktopWslEnvironment.ts line 1139Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -688,0 +747,21 @@747+748+// A candidate is Windows-reachable when it IS a Windows interface address749+// (mirrored networking, where DesktopBackendConfiguration then swaps to750+// loopback) or when it sits inside a Windows interface's subnet (NAT mode,751+// where the distro's eth0 shares the WSL vEthernet adapter's subnet). Docker752+// bridges and in-distro VPN tunnels match neither. When nothing matches,753+// fall back to the first candidate, preserving the pre-validation behavior.754+export const pickDistroIp = (755+ candidates: ReadonlyArray<string>,756+ windowsInterfaces: ReadonlyArray<WindowsIpv4Interface>,757+): string | null => {758+ for (const candidate of candidates) {759+ for (const iface of windowsInterfaces) {760+ if (candidate === iface.address) return candidate;761+ if (iface.netmask !== undefined && inSameSubnet(candidate, iface.address, iface.netmask)) {762+ return candidate;763+ }764+ }765+ }766+ return candidates[0] ?? null;767+};
- apps/desktop/src/wsl/DesktopWslEnvironment.ts line 1107Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -688,0 +737,21 @@737+738+export interface WindowsIpv4Interface {739+ readonly name: string;740+ readonly address: string;741+ readonly netmask: string | undefined;742+}743+744+const inSameSubnet = (a: string, b: string, netmask: string): boolean => {745+ const aInt = ipv4ToInt(a);746+ const bInt = ipv4ToInt(b);747+ const maskInt = ipv4ToInt(netmask);748+ if (aInt === null || bInt === null || maskInt === null) return false;749+ return (aInt & maskInt) === (bInt & maskInt);750+};751+752+const inInterfaceSubnet = (candidate: string, iface: WindowsIpv4Interface): boolean =>753+ iface.netmask !== undefined && inSameSubnet(candidate, iface.address, iface.netmask);754+755+const isWslAdapterName = (name: string): boolean => name.toLowerCase().includes("wsl");756+757+// Ranked selection, strongest signal first, so a weak match on an early
juliusmarminge 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: Team
Run ID:
c48fc102-ff05-4f73-b2b0-277b1c48cf98You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Warning
Your free Security trial is over. An organization admin can upgrade to Advanced for continuous pull request security review or dismiss this notice.
Comment `@coderabbitai help` to get the list of available commands.