microsoft / microsoft/WSL

Mirrored networking: port 5004 loopback TCP connections never complete (adjacent ports work)

Open
#41,135 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug needs-investigation network wsl2
Dominant language
C++
Stars
33.7k
Forks
1.8k
Avg merge
3d 17h
Merged PRs (30d)
116

Description

### Windows Version

Windows 11 25H2 (OS Build 26200.8875)

### WSL Version

```
WSL version: 2.7.10.0
Kernel version: 6.18.33.2-2
WSLg version: 1.0.73.2
MSRDC version: 1.2.6676
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.26100.1-240331-1435.ge-release
Windows version: 10.0.26200.8875
```

### Are you using WSL 1 or WSL 2?

- [x] WSL 2
- [ ] WSL 1

### Kernel Version

6.18.33.2-microsoft-standard-WSL2

### Distro Version

Ubuntu 24.04.1 LTS (Noble Numbat)

### Other Software

- Vite 5.4.14 (dev server) — used initially; issue reproduces without Vite
- Node.js / Python 3 sockets — minimal reproducers below

### Repro Steps

1. Configure `%USERPROFILE%\.wslconfig`:

```ini
[wsl2]
networkingMode=mirrored
memory=6GB
processors=4
swap=8GB

[experimental]
autoMemoryReclaim=Disabled
```

2. Restart WSL: `wsl --shutdown`, then reopen the distro.

3. Run this Python loopback test inside WSL (no other process on port 5004):

```python
import socket, threading, time

port = 5004

def server():
s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(("127.0.0.1", port))
s.listen(5)
s.settimeout(3)
try:
conn, addr = s.accept()
print("accepted", addr)
conn.send(b"ok")
conn.close()
except Exception as e:
print("accept failed:", e)
s.close()

threading.Thread(target=server, daemon=True).start()
time.sleep(0.3)

c = socket.socket()
c.settimeout(3)
try:
c.connect(("127.0.0.1", port))
print("client ok:", c.recv(8))
except Exception as e:
print("client failed:", e)
```

4. Optionally compare adjacent ports by changing `port` to `5003`, `5005`, or `5008`.

### Expected Behavior

- Server prints `accepted ('127.0.0.1', )`
- Client prints `client ok: b'ok'`
- Same behavior as ports 5003 and 5005

### Actual Behavior

On **port 5004 only**:

- `bind()` and `listen()` succeed
- `accept()` times out (no connection received)
- Client `connect()` times out
- TCP handshake never completes on loopback

Adjacent ports work normally:

| Port | bind | listen | accept | client connect |
|------|------|--------|--------|----------------|
| 5003 | OK | OK | OK | OK |
| **5004** | OK | OK | **TIMEOUT** | **TIMEOUT** |
| 5005 | OK | OK | OK | OK |
| 5008 | OK | OK | OK | OK |

This is **not application-specific**. The same failure occurs with:

- Raw Python `socket` (above)
- Raw Node.js `http.createServer()` on `127.0.0.1:5004`
- Vite dev server (`vite serve --port 5004`) — prints `ready` but all HTTP requests hang indefinitely

A full PC restart does **not** fix the issue.

### Impact

Local development servers bound to port 5004 appear healthy (`ss` shows `LISTEN`, Vite prints `ready`) but are completely unreachable on `127.0.0.1:5004` from inside WSL. A reverse proxy (e.g. Vite hub on port 5000) fails with `ETIMEDOUT 127.0.0.1:5004`.

**Workaround:** Use a different port (e.g. 5008) or switch to `networkingMode=NAT`.

### Diagnostic Logs

**WSL side — port 5004 socket state while hung:**

```
$ ss -tlnp | grep 5004
LISTEN 0 128 127.0.0.1:5004 0.0.0.0:* users:(("python3",pid=...,fd=5))
```

**Windows side — no listener on 5004:**

```
> netstat -ano | findstr :5004
(no output)

> Get-NetTCPConnection -LocalPort 5004
(no connections)

> netsh int ipv4 show excludedportrange protocol=tcp
Start Port End Port
---------- --------
50000 50059 *
```

Port 5004 is **not** in the Windows excluded port range (50000–50059).

**Linux reserved/ephemeral ports:**

```
$ cat /proc/sys/net/ipv4/ip_local_reserved_ports
(empty)

$ sysctl net.ipv4.ip_local_port_range
net.ipv4.ip_local_port_range = 44620 48715
```

**Routing table (local):**

```
local 127.0.0.0/8 dev lo proto kernel scope host src 127.0.0.1
local 127.0.0.1 dev lo proto kernel scope host src 127.0.0.1
```

### Related issues

This may be related to #41102 (general mirrored-mode localhost TCP handshake failure) but differs in that **only port 5004 is affected** while immediately adjacent ports (5003, 5005) work correctly. That port-specific behavior suggests a distinct mirrored-networking port routing or exclusion bug.

### Additional Information

- Issue persists across PC restarts
- Only occurs with `networkingMode=mirrored` (not tested with NAT in this report, but NAT is the known workaround from related issues)
- WSL networking logs not yet attached; will add via `collect-wsl-logs.ps1 -LogProfile networking` if requested

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied Python loopback reproducer on port 5004 and comparing it with ports 5003 and 5005 under mirrored networking. If requested, collect networking logs with collect-wsl-logs.ps1 -LogProfile networking. Done means the port 5004 TCP handshake completes in mirrored mode without regressing adjacent ports.

Written by the indexing model from the issue text.

Assessment

Tech stack
linux, node.js, python, vite
Domain
networking, operating-systems
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.