PRB: "WSAEADDRESSINUSE" Error Message When You Try to Connect Through an Anonymous Port After You Increase the IMAP Connection Limit


When you increase the IMAP connection limit, and then try to connect to the IMAP server from a Microsoft TV mail service that is configured with a very low MailboxCacheTTL setting, you receive the "WSAEADDRESSINUSE" error message (Error code :10048).


This behavior occurs because of a combination of the following:
  • By default, Windows 2000 has limited space for anonymous ports. This space is limited more by the low MailboxCacheTTL that is configured for the Microsoft TV mail service. (Anonymous ports are temporary ports that are assigned by a computer's IP stack; anonymous ports are assigned from a designated range of ports. Only ports 1024-5000 are used in Windows 2000.)
  • The SO_REUSEADDR option on the sockets is not turned on, so the sockets cannot be reused immediately after being closed. The sockets must remain reserved in a TIME_WAIT state for four minutes. If you set the SO_REUSEADDR option, Windows permits multiple binds to the listening socket.
The anonymous port (ephemeral port) range limits the maximum number of connections from one computer to a specific service on a remote computer. The TCP/IP protocol uses the connection's 4-tuple (server IP, server port, client IP, and client port) to distinguish between connections; if the anonymous port range is only 4000 ports wide (approximately), there can be only 4000 unique connections from a client computer to a remote service at one time.

When the connection ends, the ephemeral port is available for reuse, although most IP stacks do not reuse that port number until the whole pool of ephemeral ports has been used. Therefore, if the client program reconnects, the client is assigned a different ephemeral port number for the client side of the new connection. In the case of the Microsoft TV mail service, a very low MailboxCacheTTL setting aggravates the situation because IMAP connections close and reopen frequently (on almost every request).

A port range of 4000 may seem large, but it is small for current computing demands when you consider that a TCP connection must expire through the TIME_WAIT state before it is really completed. For example, even if both sides of a connection properly close their ends of the connection, because of TCP's error control, each side must wait until the TIME_WAIT state is expired before the connection's resources really can be disposed.

The TIME_WAIT state is two times the maximum segment lifetime (MSL). (For this reason, the TIME_WAIT state is also known as the 2MSL state.) Typically, depending on the IP stack, the TIME_WAIT state is configured to be 240 seconds total. Therefore, you can have only 4000 connections per 240-second window and, in practice, these 4000 connections can be used up.


To prevent this behavior, do one of the following:
  • Increase the port range that is used for anonymous ports to approximately 20,000 ports (for example) by modifying the MaxUserPort registry key. Windows uses the conventional BSD range of 1024 to 5000 for its anonymous (ephemeral) port range. You can set only the upper bound of the ephemeral port range. To modify the MaxUserPort registry key, follow these steps:

    1. Start Registry Editor (Regedt32.exe).
    2. Locate the MaxUserPort key in the registry:

    3. On the Edit menu, click Add Value, and then add the following registry value:

      Value Name: MaxUserPort
      Data Type: REG_DWORD
      Value: 65534 (for example)
      Valid Range: 5000-65534 (decimal)
      Default: 0x1388 (5000 decimal)
    4. Quit Registry Editor.
    Description: This parameter controls the maximum port number that is used when an application requests any available user port from the system. Typically, ephemeral (that is, short-lived) ports are allocated between the values of 1024 and 5000 inclusive.

  • Change the timeout on the connections from 240 seconds (the default) to any length from 30 seconds to 300 seconds. Use the TcpTimedWaitDelay registry parameter to change this value. To do this, start Registry Editor (Regedt32.exe), locate the following key in the registry, and then modify the value:



    Key: Tcpip\Parameters

    Value Type: REG_DWORD-time in seconds

    Valid Range: 30-300 (decimal)

    Default: 0xF0 (240 decimal)

    :This parameter determines 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. For more information, see RFC 793.
NOTE: This problem is made worse if the MailboxCacheTTL setting is very low. If the problem persists after you make the registry changes described previously, increase the mailbox TTL by changing the MailboxCacheTTL setting in the SiteConfig.cfg file (the configuration file for Microsoft Server Installation).

More Information

For additional information about increasing the default anonymous port range, click the article numbers below to view the articles in the Microsoft Knowledge Base:

196271 Unable to Connect from TCP Ports Above 5000
149532 Windows NT Clients Run Out of Ports

Article ID: 319502 - Last Review: Jun 19, 2014 - Revision: 1