ncat closes connection prematurely on WSL2 unless --keep-open is specified
- 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.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](https://github.com/user-attachments/files/23581844/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](https://github.com/user-attachments/files/23581853/ncat_tests2.zip)
Contributor guide
Research direction
Begin by reproducing the two-terminal ncat case on WSL2 with mirrored networking, then compare it with --keep-open, WSL1, and nc using the attached networking logs and packet captures. Done means the listener accepts and delivers “hello” without --keep-open and without a connection reset.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- linux, ubuntu
- Domain
- networking, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100