WSL icon indicating copy to clipboard operation
WSL copied to clipboard

ncat closes connection prematurely on WSL2 unless --keep-open is specified

Open CherryDT opened this issue 1 month ago • 6 comments

Windows Version

Microsoft Windows [Version 10.0.26200.7019]

WSL Version

2.6.1.0

Are you using WSL 1 or WSL 2?

  • [x] WSL 2
  • [ ] WSL 1

Kernel Version

6.6.87.2-microsoft-standard-WSL2

Distro Version

Ubuntu 24.04

Other Software

Ncat: Version 7.94SVN ( https://nmap.org/ncat )

Repro Steps

  1. Run ncat -v -l 12345 in one terminal.
  2. Run ncat -v 127.0.0.1 12345 in another terminal.
  3. Observe that the first terminal correctly shows Ncat: Connection from 127.0.0.1:46128. or similar.
  4. Try to send hello from the second terminal (enter hello and press Enter).
  5. Observe that the second ncat command terminated with error Ncat: Connection reset by peer..
  • If you try the same with extra option --keep-open in the first terminal, it all works as expected.
  • If you try the same with the first terminal using a WSL1 distro, it all works as expected.
  • If you try the same with nc instead of ncat, it all works as expected.

Note: I am using mirrored network mode.

Expected Behavior

hello can be sent and is received on the other end.

Actual Behavior

Connection dies with Ncat: Connection reset by peer. and hello is not received on the other end.

Diagnostic Logs

Networking logs: WslNetworkingLogs-2025-11-17_12-54-48.zip

Packet captures using Wireshark inside WSL2 on loopback0:

  • Port 33001: Broken ncat without --keep-open on WSL2
  • Port 33002: Working ncat with --keep-open on WSL2
  • Port 33003: Working ncat without --keep-open on WSL1
  • Port 33004: Working nc on WSL2 ncat_tests2.zip

CherryDT avatar Nov 17 '25 12:11 CherryDT

No logs.etl found in the archive. Make sure that you ran collect-wsl-logs.ps1 as administrator and that the logs.etl file is in the archive.

Diagnostic information
Multiple log files found, using: https://github.com/user-attachments/files/23581844/WslNetworkingLogs-2025-11-17_12-54-48.zip
.wslconfig found
Detected appx version: 2.6.1.0
optional-components.txt not found
No logs.etl found in archive.
Error while parsing the logs. See action page for details

github-actions[bot] avatar Nov 17 '25 12:11 github-actions[bot]

I don't know about any log.etl file, this is the ZIP your script from the wiki produced, as-is (yes it was run as admin). Please advise.

CherryDT avatar Nov 17 '25 12:11 CherryDT

/logs

OneBlue avatar Nov 17 '25 19:11 OneBlue

Diagnostic information
.wslconfig found
Detected appx version: 2.6.1.0

github-actions[bot] avatar Nov 18 '25 08:11 github-actions[bot]

Thank you. I can see in the logs that mirrored networking is enabled. @CatalinFetoiu : Could you have a look ?

OneBlue avatar Nov 25 '25 22:11 OneBlue