WSL icon indicating copy to clipboard operation
WSL copied to clipboard

Host cannot connect to localhost:5004 when using mirrored networking mode

Open cowwoc opened this issue 8 months ago • 8 comments

Windows Version

Microsoft Windows [Version 10.0.26100.3775]

WSL Version

2.4.11.0

Are you using WSL 1 or WSL 2?

  • [x] WSL 2
  • [ ] WSL 1

Kernel Version

5.15.167.4-1

Distro Version

Ubuntu 24.04

Other Software

If WSL is in Mirrored mode then a server that binds to port 5004 in WSL cannot be reached from the host. If WSL is in NAT mode, this works fine.

Other ports, such as 5003 or 5005 work fine.

Unlike https://github.com/microsoft/WSL/issues/12344 and https://github.com/microsoft/WSL/issues/12122 I am not attempting to use multicast.

Repro Steps

  1. Run python3 -m http.server 5004 --bind 0.0.0.0 inside WSL
  2. Run curl http://localhost:5004/ from the host

If WSL is in NAT mode, this works. If WSL is in Mirrored mode the command fails with curl: (7) Failed to connect to localhost port 5004 after 2250 ms: Could not connect to server.

This is reproducible 100% of the time. Restarting WSL, rebooting Windows and disabling the firewall does not help.

Expected Behavior

The host should be able to reach the server.

Actual Behavior

The host cannot connect to the server.

Diagnostic Logs

WslNetworkingLogs-2025-05-11_00-13-39.zip

WslLogs-2025-05-11_00-15-37.zip

cowwoc avatar May 11 '25 04:05 cowwoc

Diagnostic information
Multiple log files found, using: https://github.com/user-attachments/files/20147016/WslNetworkingLogs-2025-05-11_00-13-39.zip
.wslconfig found
Detected appx version: 2.4.11.0
optional-components.txt not found

github-actions[bot] avatar May 11 '25 04:05 github-actions[bot]

Diagnostic information
Multiple log files found, using: https://github.com/user-attachments/files/20147016/WslNetworkingLogs-2025-05-11_00-13-39.zip
.wslconfig found
Detected appx version: 2.4.11.0
optional-components.txt not found

github-actions[bot] avatar May 11 '25 04:05 github-actions[bot]

Diagnostic information
Multiple log files found, using: https://github.com/user-attachments/files/20147016/WslNetworkingLogs-2025-05-11_00-13-39.zip
.wslconfig found
Detected appx version: 2.4.11.0
optional-components.txt not found

github-actions[bot] avatar May 11 '25 04:05 github-actions[bot]

do you have activated the experimental loopback?

Check your .wslconfig and try to add it

[experimental]
hostAddressLoopback=true

borjamunozf avatar May 13 '25 14:05 borjamunozf

@borjamunozf I just tested it. The problem exists regardless of whether hostAddressLoopback is true or false.

cowwoc avatar May 13 '25 22:05 cowwoc

I can reproduce the behaviour with and without the hostAdressLoopback, disabling firewall & so.

Linux (Ubuntu 22)

python3 -m http.server 5004

Windows:

  • 127.0.0.1:5004 / localhost:5004 not reachable

Changing to 5003 works.

Even using the experimental option ignoredPorts to 5004 the behaviour is the same. Also checked the ports listening Windows side and I don't observe anything using 5004.

borjamunozf avatar May 15 '25 11:05 borjamunozf

Update. I don't recall to see this section before in the Troubleshooting, but it seems that the port 5004 (RTP) won't forward the traffic in these ports to the WSL VM.

Image

borjamunozf avatar May 15 '25 11:05 borjamunozf

Although I didn't mention it in the original description, the bug I personally ran into was in the opposite direction. Meaning, if a Windows service (k3s in my case) is listening on host port 5004, WSL (nodes inside the cluster) cannot reach it either. This doesn't seem to be covered explicitly by the above troubleshooting note but it makes sense that maybe the same problem exists there.

Can anyone shed some light on why these ports are not being forwarded and whether there are plans to fix it? Thank you,

cowwoc avatar May 15 '25 17:05 cowwoc