microsoft / microsoft/WSL

wslc: TCP port publishing fails after repeated client disconnects

Open
#41,052 1 comment 1 reaction 0 assignees View on GitHub
bug wslc
Dominant language
C++
Stars
33.7k
Forks
1.8k
Avg merge
3d 17h
Merged PRs (30d)
116

Description

### Windows Version

Microsoft Windows [Version 10.0.26200.8737]

### WSL Version

2.9.3.0

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

- [x] WSL 2
- [ ] WSL 1

### Kernel Version

6.18.35.2-1

### Distro Version

Ubuntu 24.04

### Other Software

- wslc 2.9.3.0
- Python 3.14.6 on Windows
- psycopg 3.3.4
- postgres:16 container image, PostgreSQL 16.14

### Repro Steps

Start PostgreSQL with a published TCP port:

```
wslc run -d --rm --name wslc-pg-repro `
-p 127.0.0.1:35434:5432 `
-e POSTGRES_USER=repro `
-e POSTGRES_PASSWORD=repro `
-e POSTGRES_DB=repro `
postgres:16
```

Install the Windows client dependency:

`py -m pip install "psycopg[binary]==3.3.4"`

Save this as repro.py:

```
import subprocess
import sys

import psycopg

dsn = (
"postgresql://repro:repro@127.0.0.1:35434/repro"
"?connect_timeout=3"
)

# Simulate a client process terminating while it still owns TCP connections.
child = f"""
import os
import psycopg

connections = []
for _ in range(80):
connection = psycopg.connect({dsn!r})
connection.execute("select 1").fetchone()
connections.append(connection)

os._exit(0)
"""

for batch in range(1, 61):
result = subprocess.run([sys.executable, "-c", child])
if result.returncode:
print(f"child failed in batch {batch}")
raise SystemExit(result.returncode)

with psycopg.connect(dsn) as connection:
connection.execute("select 1").fetchone()

print(f"completed batch {batch}")
```

Run it twice without restarting the WSLC session:

```
py repro.py
py repro.py
```

### Expected Behavior

Terminating one client process should close that process’s connections without affecting later connections through the published port.

### Actual Behavior

Starting from a fresh WSLC session, the first run completed all 60 batches. The second run began failing around batch 5, after roughly 5,000 total connections:

```
psycopg.OperationalError: connection failed:
connection to server at "127.0.0.1", port 35434 failed:
server closed the connection unexpectedly
```

Across repeated tests I have also seen:

```
Address already in use (0x00002740/10048)
Software caused connection abort (0x00002745/10053)
connection timeout expired
```

PostgreSQL remains running and accepts connections inside the container:

`/var/run/postgresql:5432 - accepting connections`

Restarting the WSLC session restores the published port.

As an A/B check, the original workload remains stable when the WSLC session uses `session.networkingMode: nat`. Removing that override and returning to the default networking mode reproduces the failures.

### Diagnostic Logs

[WslLogs-2026-07-10_15-45-11.tar.gz](https://github.com/user-attachments/files/29892235/WslLogs-2026-07-10_15-45-11.tar.gz)

Contributor guide

Open the contributing guide

Research direction

Start by running the provided repro.py against the wslc PostgreSQL container and compare the default networking mode with session.networkingMode: nat. Review the linked WslLogs archive and the observed port errors; done means repeated client-process termination no longer breaks later connections through the published port.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python
Domain
networking, operating-systems
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.