[Python-Dev] reuse of address default value (was Re: [Python-checkins] CVS: python/dist/src/Lib SocketServer.py)

Peter Funk pf@artcom-gmbh.de
Thu, 14 Dec 2000 16:56:08 +0100 (MET)


Hi,

Moshes checkin indeed makes a lot of sense.  Sorry for the irritation.

Guido van Rossum:
> The reason for the patch is that without this, if you kill a TCP server
> and restart it right away, you'll get a 'port in use" error -- TCP has
> some kind of strange wait period after a connection is closed before
> it can be reused.  The patch avoids this error.
> 
> As far as I know, with TCP, code using SO_REUSEADDR still cannot bind
> to the port when another process is already using it, but for UDP, the
> semantics may be different.
> 
> Is your server using UDP?

No and I must admit, that I didn't tested carefully enough:  From
a quick look at my process listing I assumed there were indeed
two server processes running concurrently which would have broken
the needed mutual exclusion.  But the second process went in
a sleep-and-retry-to-connect-loop which I simply forgot about.
This loop was initially built into my server to wait until the
"strange wait period" you mentioned above was over or a certain
number of retries has been exceeded.

I guess I can take this ugly work-around out with Python 2.0 and newer,
since the BaseHTTPServer.py shipped with Python 2.0 already contained
allow_reuse_address = 1 default in the HTTPServer class.

BTW: I've took my old W.Richard Stevens Unix Network Programming
from the shelf.  After rereading the rather terse paragraph about
SO_REUSEADDR I guess the wait period is necessary to make sure, that
their is no connect pending from an outside client on this TCP port.
I can't find nothing about UDP and REUSE.

Regards, Peter