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

Guido van Rossum guido@python.org
Thu, 14 Dec 2000 09:51:26 -0500


> I think the following change is incompatible and will break applications.
> 
> At least I have some server type applications that rely on 
> 'allow_reuse_address' defaulting to 0, because they use
> the 'address already in use' exception, to make sure, that exactly one
> server process is running on this port.  One of these applications, 
> which is BTW build on top of Fredrik Lundhs 'xmlrpclib' fails to work,
> if I change this default in SocketServer.py.  
> 
> Would you please explain the reasoning behind this change?

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?

Try this patch if your problem is indeed related to UDP:

*** SocketServer.py	2000/12/13 20:39:17	1.20
--- SocketServer.py	2000/12/14 14:48:16
***************
*** 268,273 ****
--- 268,275 ----
  
      """UDP server class."""
  
+     allow_reuse_address = 0
+ 
      socket_type = socket.SOCK_DGRAM
  
      max_packet_size = 8192

If this works for you, I'll check it in, of course.

--Guido van Rossum (home page: http://www.python.org/~guido/)