Symptoms

The Subversion (SVN) server is on a windows system, and the initial index of the source code repository fails with the following error:

Messages: Unable to connect to a repository at URL 'svn://ipaddress/usr/local/Repository/trunk/...' [SharpSvn.SvnSystemException] Can't connect to host 'ipaddress': Only one usage of each socket address (protocol/network address/port) is normally permitted.

Cause

This issue happens because:

  1. When Spira makes authenticated calls to SVN, the SVN client is closing connections. And when Spira is making authenticated calls repeatedly to the same server in the process of establishing the initial cache, you are effectively making and closing connections repeatedly
  2. The same might happen when you are making regular http [un authenticated] calls but setting keep-alive = false.

This results in Windows running out of available ports to use (see this article from Microsoft on the subject).

Solution

Microsoft recommends one of the two following fixes:

  1. One of the ways is to increase the dynamic port range. The max by default is 5000. You can set this up to 65534.
    HKLM\System\CurrentControlSet\Services\Tcpip\Parameters\MaxUserPort is the key to use.

  2. The second thing you can do is once the connection does get into an TIME_WAIT state you can reduce the time it is in that state, The Default is 4 minutes, but you can set this to 30 seconds
    HKLM\System\CurrentControlSet\Services\Tcpip\Parameters\TCPTimedWaitDelay is the key to use.
    Set this to 30 seconds