Thursday, July 24, 2014

Tech | HowTo Resolve: Only one usage of each socket address (protocol/network address/port) is normally permitted

This error occurs when an operating system fails to open a port to communicate to the domain for the service permissions check. This is generally a transitory error and is unrelated to the service.

You may be able to wait for five minutes, and then restart the service successfully.

If the error persists, it can usually be resolved in Windows by setting the registry keys in the articles below. The referenced keys do not exist by default in the registry, so you have to make them to change the system settings from their default.

Another possible reason is that you are overloading the TCP/IP stack. Windows (and I think all socket stacks actually) have a limitation on the number of sockets that can be opened in rapid sequence due to how sockets get closed under normal operation. Whenever a socket is closed, it enters the TIME_WAIT state for a certain time (240 seconds IIRC).

Each time you poll, a socket is consumed out of the default dynamic range (I think it’s about 5000 dynamic ports just above 1024), and each time that poll ends, that particular socket goes into TIME_WAIT. If you poll frequently enough, you will eventually consume all of the available ports, which will result in TCP error 10048.

Generally, WCF tries to avoid this problem by pooling connections and things like that. This is usually the case with internal services that are not going over the internet. I am not sure if any of the wsHttp bindings support connection pooling, but the netTcp binding should. I would assume named pipes does not run into this problem. I couldn't say for the MSMQ binding.

There are two solutions you can use to get around this problem. You can either increase the dynamic port range, or reduce the period of TIME_WAIT. The former is probably the safer route, but if you are consuming an extremely high volume of sockets (which doesn't sound like the case for your scenario), reducing TIME_WAIT is a better option (or both together.)

Changing the Dynamic Port Range
  1. Open regedit.
  2. Open key HKLM\System\CurrentControlSet\Services\Tcpip\Parameters
  3. Edit (or create as DWORD) the MaxUserPort value.
  4. Set it to a higher number. (i.e. 65534)

Changing the TIME_WAIT delay
  1. Open regedit.
  2. Open key HKLM\System\CurrentControlSet\Services\Tcpip\Parameters
  3. Edit (or create as DWORD) the TCPTimeWaitDelay.
  4. Set it to a lower number. Value is in seconds. (i.e. 60 for 1 minute delay)

One of the above solutions should fix your problem. If it persists after changing the port range, I would see try increasing the period of your polling so it happens less frequently. That will give you more leeway to work around the time wait delay. I would change the time wait delay as a last resort.

About TcpTimedWaitDelay
21 out of 24 rated this helpful - Rate this topic

Data type
Default value
0x1E 0x12C ( 30–300 seconds )
0xF0 ( 240 seconds = 4 minutes )

Determines the time that must elapse before TCP can release a closed connection and reuse its resources. This interval between closure and release is known as the TIME_WAIT state or 2MSL state. During this time, the connection can be reopened at much less cost to the client and server than establishing a new connection.

RFC 793 requires that TCP maintains a closed connection for an interval at least equal to twice the maximum segment lifetime (2MSL) of the network. When a connection is released, its socket pair and TCP control block (TCB) can be used to support another connection.

By default, the MSL is defined to be 120 seconds, and the value of this entry is equal to two MSLs, or 4 minutes. However, you can use this entry to customize the interval.

Reducing the value of this entry allows TCP to release closed connections faster, providing more resources for new connections. However, if the value is too low, TCP might release connection resources before the connection is complete, requiring the server to use additional resources to reestablish the connection.

Normally, TCP does not release closed connections until the value of this entry expires. However, TCP can release connections before this value expires if it is running out of TCP control blocks (TCBs). The number of TCBs the system creates is specified by the value of the MaxFreeTcbs entry.

Windows 2000 does not add this entry to the registry. You can add it by editing the registry or by using a program that edits the registry.

Dan A. 

No comments:

Post a Comment

Please leave your comment here...