WSL icon indicating copy to clipboard operation
WSL copied to clipboard

wslc: TCP port publishing fails after repeated client disconnects

Open JJLiebig opened this issue 4 months ago • 3 comments

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

WslLogs-2026-07-10_15-45-11.tar.gz

JJLiebig avatar Jul 10 '26 13:07 JJLiebig

Diagnostic information
.wslconfig found
Detected appx version: 2.9.3.0

github-actions[bot] avatar Jul 10 '26 13:07 github-actions[bot]

May be a duplicate of #41691, assigning to Kevin to assess or fix as needed.

dkbennett avatar Oct 09 '26 20:10 dkbennett

Resolved by microsoft/openvmm#3600, incorporated into WSL through the DeviceHost 1.2.61 update in microsoft/WSL#41426.

kvega005 avatar Oct 14 '26 17:10 kvega005