Connect to a closed loopback port takes 2 seconds per address on Windows; libuv, curl and Chromium avoid it with SIO_TCP_INITIAL_RTO
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- csharp
- Domain
- networking
Research direction
Start by reading the Windows socket connection code in System.Net.Sockets and the related tests for loopback connections. Check how the proposed SIO_TCP_INITIAL_RTO ioctl is supported across Windows versions and where failures can be safely ignored. Done means refused loopback connections fail faster while successful connections and non-loopback connections remain unaffected.
Written by the indexing model from the issue text.
Description
Description
On Windows, connecting to a loopback port where nothing listens takes about 2 seconds before SocketException ConnectionRefused. For localhost it's about 4 seconds, because ::1 and then 127.0.0.1 each wait. On Linux the same call fails in about a millisecond.
Repro with .NET 10.0.14 on Windows 11 26100.
var s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
s.Connect(IPAddress.Loopback, 59321); // ~2,030 ms, then ConnectionRefused
HttpClient.GetAsync("http://localhost:59321/") takes about 4,080 ms. On WSL2 on the same machine, both take 1 to 3 ms.
Configuration
.NET 10.0.14, Windows 11 26100 x64 (Intel Core i9-10900K). Linux numbers are from WSL2 on the same machine with the same .NET.
Regression?
No. #65375 and #31085 reported the localhost part and were closed as OS behavior.
Data
From .NET the same thing works today with socket.IOControl(unchecked((int)0x98000011), new byte[] { 0, 0, 254, 0 }, null) before Connect. With it the refused connect takes 2.6 ms for 127.0.0.1 and 1.1 ms for ::1, and an HttpClient with a ConnectCallback that does this gets http://localhost down from 4,083 ms to 9.5 ms. Connects that succeed are unchanged.
Analysis
The time is Windows retransmitting the SYN after the RST. It can be turned off per socket, and libuv (Node), curl (curl/curl#22494) and Chromium do that for loopback destinations.
TCP_INITIAL_RTO_PARAMETERS p = { TCP_INITIAL_RTO_DEFAULT_RTT, TCP_INITIAL_RTO_NO_SYN_RETRANSMISSIONS };
WSAIoctl(sock, SIO_TCP_INITIAL_RTO, &p, sizeof(p), NULL, 0, &bytes, NULL, NULL);
There's no system-wide way to get this. Set-NetTCPSetting accepts MaxSynRetransmissions from 2 to 8 only.
Would you take a change that sets this ioctl in System.Net.Sockets on Windows when the remote address is loopback, ignoring failures (older Windows)? It only affects loopback, where there's no link to lose a SYN on. It matters for tools and test suites that poll for a local server to come up. PowerShell's Invoke-WebRequest pays 4 s per miss on localhost today.
- Dominant language
- C#
- Stars
- 18.5k
- Forks
- 5.8k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 588
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/runtime
-
area-CodeGen-coreclr untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
dotnet/runtime#138181 · 1 comment ·
Maintainers usually reply within 1 day
-
area-System.Collections untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
dotnet/runtime#138090 · 1 comment ·
Maintainers usually reply within 1 day
-
area-System.Text.Json untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
dotnet/runtime#138089 · 1 comment ·
Maintainers usually reply within 1 day
-
area-Setup untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
dotnet/runtime#137376 · 1 comment ·
Maintainers usually reply within 1 day
-
area-System.Memory untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
dotnet/runtime#137334 · 4 comments ·
Maintainers usually reply within 1 day
Similar issues
-
Add `net10.0`Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
dotnet-outdated/dotnet-outdated#871 ·
Maintainers usually reply within 1 day
-
triage/untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
unoplatform/uno#26676 ·
Maintainers usually reply within 1 day
-
.NET bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
jhaizhou-ops/S2Arm#2177 · 3 comments ·
Maintainers usually reply within 1 day