Skip to content

fix(xdebug): Use a more sophisticated search for windows host ip address on WSL mirrored mode#7880

Merged
stasadev merged 10 commits intomainfrom
20251118_better_mirrored_wsl
Nov 25, 2025
Merged

fix(xdebug): Use a more sophisticated search for windows host ip address on WSL mirrored mode#7880
stasadev merged 10 commits intomainfrom
20251118_better_mirrored_wsl

Conversation

@rfay
Copy link
Copy Markdown
Member

@rfay rfay commented Nov 19, 2025

The Issue

The previous technique for finding the windows-side IP address for host.docker.internal when using mirrored networking mode could fail if there were VMWare or Virtualbox interfaces on the machine. It made my machine stop being able to do xdebug because of our experiments with VMWare.

How This PR Solves The Issue

This replaces the previous PowerShell-based host-IP detection (which simply
selected the first non–link-local IPv4 address on Windows) with a more accurate
approach. Instead of scanning all network adapters, the new implementation
selects the IPv4 address associated with the best default route
(0.0.0.0/0)
on Windows. This is the same logic Windows uses to determine
its primary outbound interface.

By basing detection on the default route instead of interface ordering or
adapter names, this method:

  • Ignores host-only / virtual adapters such as VMware VMnet, VirtualBox
    Host-Only, and other isolated networks that cannot accept incoming
    connections from WSL2 containers.
  • Avoids choosing incorrect IPs like 192.168.56.1, which are reachable
    via ping but cannot carry TCP connections back to IDE listeners (e.g., on
    port 9003).
  • Requires no vendor-specific filtering and works in typical environments
    without customization.
  • Improves reliability of mirrored-networking mode, where Windows exposes
    multiple NICs and the old heuristic frequently selected the wrong one.

As a result, host.docker.internal now maps to an IP that actually accepts
connections from the DDEV web container in WSL2 mirrored mode, fixing Xdebug
connectivity failures and other host-access problems.

Manual Testing Instructions

Use Xdebug on mirrored networking mode

Automated Testing Overview

I think the existing TestDdevXdebugEnabled test should properly test this.

Release/Deployment Notes

Assisted heavily in debugging and code creation by ChatGPT

Copy link
Copy Markdown

Copilot AI left a comment

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 fixes xdebug connectivity issues on Windows with WSL2 mirrored networking mode by improving how the Windows host IP address is detected. The previous implementation would incorrectly select IP addresses from VMware or VirtualBox host-only adapters, breaking xdebug connections.

  • Replaces simple "first non-link-local IPv4" selection with default-route-based detection
  • Filters routes to find the primary outbound interface using Windows' best default route (0.0.0.0/0)
  • Improves error handling with CombinedOutput and more descriptive error messages

@github-actions
Copy link
Copy Markdown

github-actions bot commented Nov 19, 2025

@rfay rfay force-pushed the 20251118_better_mirrored_wsl branch 5 times, most recently from bf59f1f to f307fc6 Compare November 20, 2025 23:45
@rfay rfay changed the title fix(xdebug): Use a more sophisticated search for windows host ip address fix(xdebug): Use a more sophisticated search for windows host ip address on WSL mirrored mode Nov 21, 2025
@rfay rfay force-pushed the 20251118_better_mirrored_wsl branch from 0a2c4c2 to d4d31b1 Compare November 23, 2025 16:06
@rfay rfay force-pushed the 20251118_better_mirrored_wsl branch from d4d31b1 to fa040e0 Compare November 24, 2025 22:17
@rfay rfay marked this pull request as ready for review November 24, 2025 22:17
@rfay rfay requested a review from a team as a code owner November 24, 2025 22:17
@rfay rfay requested a review from stasadev November 24, 2025 22:19
Copy link
Copy Markdown
Member

@stasadev stasadev left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@stasadev stasadev merged commit f57fc36 into main Nov 25, 2025
28 of 31 checks passed
@stasadev stasadev deleted the 20251118_better_mirrored_wsl branch November 25, 2025 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants