Export (0) Print
Expand All

Avoiding TCP/IP Port Exhaustion

When a client initiates a TCP/IP socket connection to a server, the client typically connects to a specific port on the server and requests that the server respond to the client over an ephemeral, or short lived, TCP or UDP port. On Windows Server 2003 and Windows XP the default range of ephemeral ports used by client applications is from 1025 through 5000. Under certain conditions it is possible that the available ports in the default range will be exhausted.

TCP/IP Port Exhaustion Causes Unexpected Errors on Applications that Connect to BizTalk Server or When BizTalk Applications Connect to a Remote Server

The symptoms of TCP/IP port exhaustion may vary from one client application to another but are typically manifested as an error indicating a failed network connection. To determine if failed network connections are being caused by TCP/IP port exhaustion, follow these steps on the client computer:

  1. On a computer running Windows XP or Windows Server 2003, click Start, click Run, type cmd, and then click OK to open a command prompt.

  2. Do one of the following:

    • Enter the following command in the command prompt on a Windows XP or Windows Server 2003 computer to display the active connections being used by the TCP/IP protocol on this computer:

      netstat -n
      
      This will list the TCP/IP addresses bound to the client computer and the ports on which the TCP/IP addresses are communicating with a remote server. If the listed ports consume all of the available ports then TCP/IP port exhaustion occurs.

    • Enter the following command in the command prompt on a Windows Server 2003-based client computer to display the active connections being used by the TCP/IP protocol:

      netstat -b
      
      This will list the TCP/IP address bound to the client computer, the port on which the TCP/IP address are communicating with a remote server, and the application that is using the ports. This information can help determine which client applications are consuming excessive TCP/IP ports.

Problems Associated with TCP/IP Port Exhaustion

Errors similar to the following have been observed when a client application attempts to connect to a BizTalk server using TCP/IP sockets or when a BizTalk application attempts to connect to a server using TCP/IP sockets:

System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send.

- or -

Unable to connect to the remote server
System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted.

When these errors occur, the following problems may also occur:

  • Client applications may fail to connect to the BizTalk server.

  • The BizTalk Application service may fail to connect to a remote SQL server.

  • BizTalk Server adapters may fail to connect to a remote server.

  • Each port reservation that is made by a client application consumes kernel memory. If an unusually high number of client port reservations are made then Windows kernel memory use will increase accordingly.

Cause

TCP/IP port exhaustion can occur on a client computer if the client computer is engaging in an unusually high number of TCIP/IP socket connections. This can occur if many client applications are initiating connections.

If all of the available ephemeral ports are allocated to client applications then the client experiences a condition known as TCP/IP port exhaustion. When TCP/IP port exhaustion occurs, client port reservations cannot be made and errors will occur in client applications that attempt to connect to a server via TCP/IP sockets.

TCP/IP port exhaustion is more likely to occur under high load conditions than under normal load conditions.

Resolution

Follow these steps to avoid TCP/IP port exhaustion and its associated problems:

  1. Verify that one or more client applications are not generating excessive TCP/IP socket connections. This can be checked by running netstat -n on Windows Server 2003 and Windows XP or by running netstat -b on Windows Server 2003 and 2008 as described above.

    If a particular client application is engaging in an unusually high number of TCP/IP socket connections then consider redesigning the client application to make more judicious use of TCP/IP socket connections.

    noteNote
    If an unusually high number of client port reservations are allocated to an instance of the BizTalk Application service (BTSNTSvc.exe) then verify that any custom code configured to run in the BizTalk Application service is not making excessive TCP/IP socket connections.

  2. If a large number of client applications are initiating the expected number of TCP/IP socket connections but there are not enough available ephemeral ports to satisfy the connection requests then implement one or more of the following registry modifications.

    WarningWarning
    If you use Registry Editor incorrectly, you may cause serious problems that may require you to reinstall your operating system. Microsoft cannot guarantee that you can solve problems that result from using Registry Editor incorrectly. Use Registry Editor at your own risk. Before you modify the Registry, always back up the registry, and verify that you know how to restore the backup if a problem occurs. For more information about how to back up, restore, and modify the registry, see the Microsoft Knowledge Base article "Description of the Microsoft Windows registry" at http://go.microsoft.com/fwlink/?LinkId=62729.

    Increase the upper range of ephemeral ports that are dynamically allocated to client TCP/IP socket connections.

    1. Start Registry Editor.

    2. Browse to, and then click the following key in the registry:

      HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters

    3. On the Edit menu, click New, DWORD Value, and then add the following registry value to increase the number of ephemeral ports that can by dynamically allocated to clients:

       

      Value name

      MaxUserPort

      Value data

      <Enter a decimal value between 5000 and 65534 here>

    4. Close Registry Editor.

      noteNote
      You must restart your computer for this change to take effect.

      noteNote
      Increasing the range of ephemeral ports used for client TCP/IP connections consumes Windows kernel memory. Do not increase the upper limit for this setting to a value higher than is required to accommodate client application socket connections so as to minimize unnecessary consumption of Windows kernel memory.

    Reduce the client TCP/IP socket connection timeout value from the default value of 240 seconds

    1. Start Registry Editor.

    2. Browse to, and then click the following key in the registry:

      HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters

    3. On the Edit menu, click New, DWORD Value, and then add the following registry value to reduce the length of time that a connection stays in the TIME_WAIT state when the connection is being closed. While a connection is in the TIME_WAIT state, the socket pair cannot be reused:

       

      Value name

      TcpTimedWaitDelay

      Value data

      <Enter a decimal value between 30 and 240 here>

    4. Close Registry Editor.

      noteNote
      You must restart your computer for this change to take effect.

      noteNote
      The valid range of this value is 30 through 300 (decimal). The default value is 240.

  3. Follow the recommendations in Avoiding DBNETLIB Exceptions for disabling the denial of service attack security feature that is implemented with Windows Server 2003 SP1 and later.

    ImportantImportant
    This should only be done in an intranet environment where the BizTalk Server computer is not directly exposed to the Internet.

  4. Follow the recommendations in Avoiding DBNETLIB Exceptions for alleviating conditions that can cause the MessageBox database(s) to become I/O bound.

  © 2009 Microsoft Corporation. All rights reserved.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft