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

Hi, 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? Moshe Zadka:
Regards, Peter -- Peter Funk, Oldenburger Str.86, D-27777 Ganderkesee, Germany, Fax:+49 4222950260 office: +49 421 20419-0 (ArtCom GmbH, Grazer Str.8, D-28359 Bremen)

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/)

Hi, Moshes checkin indeed makes a lot of sense. Sorry for the irritation. Guido van Rossum:
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

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/)

Hi, Moshes checkin indeed makes a lot of sense. Sorry for the irritation. Guido van Rossum:
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
participants (2)
-
Guido van Rossum
-
pf@artcom-gmbh.de