Client-side TCP socket receiving "Address already in use" upon connect

Alex Martelli aleax at mac.com
Sun Sep 3 11:39:48 EDT 2006


Steve Holden <steve at holdenweb.com> wrote:
   ...
> >>set registry key: 
>
>>KEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\M
axUserPort
> >>
> >>to a new DWORD value... (5000 - 65534)
> >>The default in XP is 3976 -> http://support.microsoft.com/kb/Q149532

I wonder why (performance under RAM-costrained conditions? but then why
not have this vary depending on available RAM -- complications?)

> Yes, it's the transport layer that puts the socket into the TIME_WAIT state.

Yes, there's a good explanation at
<http://www.developerweb.net/forum/showthread.php?t=2941> (though one
should really study Stevens' "TCP-IP Illustrated" for better
understanding in depth).  Playing with SO_LINGER and/or the MSL is not
recommended unless you're operating only on a network that you entirely
control (particularly in terms of round-trip times and router behavior).

As debated at
<http://www.sunmanagers.org/pipermail/summaries/2006-January/007068.html
>, you may be able to have your clients go into CLOSE_WAIT (instead of
TIME_WAIT) by playing around with "who closes the socket first", and
CLOSE_WAIT might be more transient than the 2*MSL (240 seconds...)
needed for TIME_WAIT on possibly-unreliable networks.  But it's far from
sure that this would gain you much.

Reflecting on the OP's use case, since all connections are forever being
made to the same 16 servers, why not tweak thinks a bit to hold those
connections open for longer periods of time, using a connection for many
send/receive "transactions" instead of opening and closing such
connections all of the time?  That might well work better...


Alex



More information about the Python-list mailing list