Windows Server 2012 R2 runs out of ephemeral ports, though it shouldn't

Solution 1:

I've had similar problem with exhausted pool of TCP/IP ports on WinSvr 2012R2 x64 for almost 1 month where server stopped receiving any new and TCP connections. So I played with registry values and these are stable for me:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters]
"TcpTimedWaitDelay"=dword:0000001e
"MaxUserPort"=dword:0000fffe
"TcpNumConnections"=dword:00fffffe
"TcpMaxDataRetransmissions"=dword:00000005
  • TcpTimedWaitDelay - 30
  • MaxUserPort - 65534
  • TcpNumConnections - should be in default state stretched to maximum = 16777214 should prevent server from exhausting ephemeral ports.
  • TcpMaxDataRetransmissions - Timeout limit of TCP unacknowledged data segments retransmission on actual connection = 5.

In result same like yours. I think you should consider to audit your behavior of your applications/scripts performance. If everything is ok and nothing help, then you can try to put proxy server before your web application server, make 2 nodes with web server (IIS, Apache, ...) which will share same static content and access same database at the same time (if you have enough resources in your company).

Maybe this article would help you in some way: http://blogs.technet.com/b/tristank/archive/2008/03/11/maxuserport-what-it-is-what-it-does-when-it-s-important.aspx

Solution 2:

In addition to the Tcpip driver settings, the ephemeral TCP port range is managed in Windows Server using the netsh command (source).

You can view the dynamic port range with the following commands:

  • netsh int ipv4 show dynamicport tcp
  • netsh int ipv4 show dynamicport udp
  • netsh int ipv6 show dynamicport tcp
  • netsh int ipv6 show dynamicport udp

To change the port range, use this command:

  • netsh int <ipv4|ipv6> set dynamic <tcp|udp> start=number num=range

For example:

netsh int ipv4 set dynamicport tcp start=49152 num=16384

The setting (start=49152 num=16384) is also the default on Windows Server 2008 onwards.