How to change the TIME-WAIT delay and the highest source port number that can be assigned in Windows XP or Windows Server 2003
September 15, 2010 Comments
We ran into an issue last night where a web server we use for testing wasn’t able to open anymore connections. It turned out that our web application was creating too many connections too fast and Windows ran out of port numbers to allocate.
By default, Windows XP and Windows Server 2003 (not sure about other versions of Windows) wait 4 minutes before releasing sockets in TIME-WAIT state (RFC 793) and the highest port number it can allocate is 5000. There are registry keys you can add to get around these limitations (in our case this is just a temporary workaround of course, we obviously need to fix our code :D).
- Open the Registry Editor (Start -> Run -> regedit).
- Go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters.
- Add a new DWORD value:
- To set the TIME-WAIT delay, create a new DWORD value called TCPTimedWaitDelay and assign a decimal value from 30 to 300 (the number of seconds to wait before closing the socket and releasing the port number assigned to it).
- To increase the the highest source port number that Windows can allocate, create a new DWORD value called MaxUserPorts and assign a decimal value up to 65,535 (a user port is normally above 1024 so don’t set this too low, most likely you’ll need it over 5000 anyway if you’re reading this).
- Close the Registry Editor and reboot your machine.
Source: http://msdn.microsoft.com/en-us/library/ms819739.aspx