01-06-2009 2:43 PM
Erryl
Bugs revisited: Ephemeral ports
Normal
0
false
false
false
MicrosoftInternetExplorer4
I
have revisited the list of bugs that we came across our last project and here’s
one I would like to share…
After
months of rigorous testing of our new web services we encountered a major
showstopper, our web service would not install. We got an “AddressAlreadyInUseException”.
The
exception was caused by a port colliding between our web services and some of
our applications. We were surprised that it took months for the port collision
to surface. Closing all the running applications, we tried to replicate the
scenario but tough luck trying for the nth time it was not reproducible.
What we did after was to reopen those applications from our suite and alas we
were able to catch the culprit. It turned out that our applications use
ephemeral ports intermittently causing port collision with our web services as
we install them.
So
what is an ephemeral port?
An
ephemeral port or “short lived port” is a dynamically allocated port
generally used for the client-end of a client-server communication. In a client-server
interaction, the server’s application typically listens on a well known port
whereas the client’s application queries the operating system for a dynamically
allocated TCP or UDP port that is not used by other applications.
What
we thought was a safe port range (ports higher than 5000) for our web services
has changed. We're aware that earlier Windows versions (XP and 2003)
used 1025 through 5000 as their default port range. However we found out
that for Windows Vista and Windows Server 2008, Microsoft complied with the port range recommended by the Internet Assigned Numbers Authority (IANA) - to use 49152 through 65535 as dynamic and/or private default port range.
So
to lessen the chances of port collision at least for our applications and web
services what we did (as Microsoft recommends it) was prior to installation of
our application suite on a Vista or Server 2008 operating system, we ensure to
revert back to the default port range of the old Windows versions, 1025 through
5000 using the netsh command;
netsh int <ipv4|ipv6> set dynamic
<tcp|udp> start=number num=range
in
our case we used: netsh int ipv4 set dynamic tcp start=1025 num=3975
And
to verify the dynamic tcp port range in Vista
or Server 2008 we used
netsh int ipv4 show dynamicport tcp
Some
netsh commands are as well available for different protocols:
- netsh int ipv4 show
dynamicport udp
- netsh int ipv6 show
dynamicport tcp
- netsh int ipv6 show
dynamicport udp
Normal
0
false
false
false
MicrosoftInternetExplorer4
A few important things I have read about port range:
- The smallest range of ports you can set is
255.
- The lowest starting port that you can set is 1025.
- The highest end port (based on the range you set) cannot exceed 65535.
Normal
0
false
false
false
MicrosoftInternetExplorer4
For more info read Article
929851
Filed under: IANA, AddressAlreadyInUseException, netsh, Ephemeral Port