wslc: TCP port publishing fails after repeated client disconnects
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:[email protected]: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
Diagnostic information
.wslconfig found
Detected appx version: 2.9.3.0
May be a duplicate of #41691, assigning to Kevin to assess or fix as needed.
Resolved by microsoft/openvmm#3600, incorporated into WSL through the DeviceHost 1.2.61 update in microsoft/WSL#41426.