Accepting a connection on a socket on Windows 7 takes more than a second

sockettcpipwindows 7

Here's what I've done:

  • I wrote a minimal web server (using Qt, but I don't think it's relevant here).
  • I'm running it on a legal Windows 7 32-bit.

The problem:

  • If I make a request with Firefox, IE, Chrome or Safari it takes takes about one second before my server sees that there is a new connection to be accepted.

Clues:

  • Using other clients (wget, own test client that just opens a socket) than Firefox, IE, Chrome, Safari seeing the new connection is matter of milliseconds.
  • I installed Apache and tried the clients mentioned above. Serving the request takes ~50ms as expected.
  • The problem isn't reproducible when running Windows XP (or compiling and running the same code under Linux)
  • The problem seems to present itself only when connecting to localhost. A friend connected over the Internet and serving the connection was a matter of milliseconds.
  • Running the server in different ports has no effect on the 1 second latency

Here's what I've tried without luck:

  • Stopped the Windows Defender service
  • Stopped the Windows Firewall service

Any ideas? Is this some clever 'security feature' in Windows 7? Why isn't Apache affected? Why are only the browsers affected?

Best Answer

I'm with MidnighToker - is it only when you hit "localhost" or is the delay there via the local IP address as well? If it's only when you aim for 'localhost' check your hosts file for odd entries. Windows Vista and 7 also include a HOSTS entry for IPv6 ("::1 localhost").

Since I've personally seen unused IPv6 connections slow down web browsing connections on Ubuntu in Firefox when it's enabled and not used, and read that others have seem similar in Windows, so that may be something to consider (I haven't personally encountered that problem in either Vista or Win7).

Under Ubuntu Firefox has it's own 'don't use IPv6' setting that fixes the delay without making system-wide network changes; so perhaps Firefox for Windows also has it (dunno, I use IE in Windows):

Here's how to disable it in Firefox, to perhaps at least start testing the theory:

1.Type about:config in the address bar, press Enter.

2.Find network.dns.disableIPv6 in the list.

3.Right-click -> Toggle (you want it set to 'true' to disable)

4.Restart your Mozilla application and try again.