473,323 Members | 1,560 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Why does SocketServer default allow_reuse_address = false?

Considering that UNIX Network Programming, Vol 1 (by W. Richard Stevens)
recommends "_All_ TCP servers should specify [SO_REUSEADDR] to allow the
server to be restarted [if there are clients connected]," and that
self.allow_reuse_address = False makes restarting a server a pain if there
were connected clients, why does SocketServer default allow_reuse_address
to False? It's kind of bemusing to subclass ThreadingTCPServer just to
change one variable that arguably should have been True in the first place.

Is there some history to this of which I'm not aware? Is there a good
reason for it to default to false?

j

--
Joshua Kugler
Lead System Admin -- Senior Programmer
http://www.eeinternet.com
PGP Key: http://pgp.mit.edu/ Â*ID 0xDB26D7CE

--
Posted via a free Usenet account from http://www.teranews.com

Feb 27 '07 #1
5 5915
Joshua J. Kugler wrote:
Considering that UNIX Network Programming, Vol 1 (by W. Richard Stevens)
recommends "_All_ TCP servers should specify [SO_REUSEADDR] to allow the
server to be restarted [if there are clients connected]," and that
self.allow_reuse_address = False makes restarting a server a pain if there
were connected clients, why does SocketServer default allow_reuse_address
to False? It's kind of bemusing to subclass ThreadingTCPServer just to
change one variable that arguably should have been True in the first place.

Is there some history to this of which I'm not aware? Is there a good
reason for it to default to false?
If any, don't know. Searched in already reported bugs to check if
somebody already noticed.

If not, please consider to open a bug.

Regards,

--
.. Facundo
..
Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/

Mar 5 '07 #2
On Feb 26, 5:54 pm, "Joshua J. Kugler" <jos...@eeinternet.comwrote:
Considering that UNIX Network Programming, Vol 1 (by W. Richard Stevens)
recommends "_All_ TCP servers should specify [SO_REUSEADDR] to allow the
server to be restarted [if there are clients connected]," and that
self.allow_reuse_address = False makes restarting a server a pain if there
were connected clients, why does SocketServer default allow_reuse_address
to False? It's kind of bemusing to subclass ThreadingTCPServer just to
change one variable that arguably should have been True in the first place.

Is there some history to this of which I'm not aware? Is there a good
reason for it to default to false?
Yes, it is there for a good reason. Security is the primary focus of
that option. If you enable that option, rogue applications can assume
service processing under a number of server failure conditions. In
other words, start your rogue, crash the primary service, and you now
have a rogue service running. Even periodic checks will show the
server is still running. Under a number of other configurations, it
is also possible for the rogue service to simply start and usurp some
types of IP traffic on certain OSs which would otherwise be delivered
to your real server.

Contrary to the book, blindly enabling SO_REUSEADDR is a very, very
bad idea unless you completely understand the problem domain. I'm
sure Stevens' does understand so it makes for a good choice for him.
On the other hand, most people don't understand the implications so it
makes for a very, very poor move from a security perspective.

Long story short, it is not a bug. It is a feature. The proper
default is that of the OS, which is to ensure SO_REUSEADDR is disabled
unless you absoluetely understand what you're buying by enabling it.
Greg

Mar 7 '07 #3
Greg Copeland wrote:
>Is there some history to this of which I'm not aware? Is there a good
reason for it to default to false?
<SNIP Greg's very informative reply>
Long story short, it is not a bug. It is a feature. The proper
default is that of the OS, which is to ensure SO_REUSEADDR is disabled
unless you absoluetely understand what you're buying by enabling it.
Thanks for your reply. Those are all point of which I had not been aware.

My problem (and the reason I set reuse to True) is this: if I have
connections active when I restart my service, upon restart, the socket will
fail to bind because there is still a connection in a WAIT state. And
until that old connection goes away (30 seconds or so?) I cannot restart
the service. So, the only option would be to sit there in a loop calling
serve_forever until it doesn't throw a "can't bind to socket" exception.

Or is there something I'm *really* missing about the way SocketServer is
supposed to work? Am I supposed to notify my connection threads to shut
down and disconnect "properly?" Which gets even more fun since they are
sitting there waiting for input on the connection and not in a position to
respond to other events...gets back to the fun of "killing" threads that
are blocking.

j

--
Joshua Kugler
Lead System Admin -- Senior Programmer
http://www.eeinternet.com
PGP Key: http://pgp.mit.edu/ Â*ID 0xDB26D7CE

--
Posted via a free Usenet account from http://www.teranews.com

Mar 7 '07 #4
On 3/7/07, Joshua J. Kugler <jo****@eeinternet.comwrote:
Greg Copeland wrote:
Is there some history to this of which I'm not aware? Is there a good
reason for it to default to false?
<SNIP Greg's very informative reply>
Long story short, it is not a bug. It is a feature. The proper
default is that of the OS, which is to ensure SO_REUSEADDR is disabled
unless you absoluetely understand what you're buying by enabling it.

Thanks for your reply. Those are all point of which I had not been aware.

My problem (and the reason I set reuse to True) is this: if I have
connections active when I restart my service, upon restart, the socket will
fail to bind because there is still a connection in a WAIT state. And
until that old connection goes away (30 seconds or so?) I cannot restart
the service. So, the only option would be to sit there in a loop calling
serve_forever until it doesn't throw a "can't bind to socket" exception.

Or is there something I'm *really* missing about the way SocketServer is
supposed to work? Am I supposed to notify my connection threads to shut
down and disconnect "properly?" Which gets even more fun since they are
sitting there waiting for input on the connection and not in a position to
respond to other events...gets back to the fun of "killing" threads that
are blocking.

j
This is just the way sockets work on your platform. How exactly
sockets shut down, and the exact effect that SO_REUSEADDR varies from
platform to platform. In your case, using it is probably reasonable.
Mar 7 '07 #5
Chris Mellon wrote:
>My problem (and the reason I set reuse to True) is this: if I have
connections active when I restart my service, upon restart, the socket
will
fail to bind because there is still a connection in a WAIT state.

This is just the way sockets work on your platform. How exactly
sockets shut down, and the exact effect that SO_REUSEADDR varies from
platform to platform. In your case, using it is probably reasonable.
Thank you. Glad to know I've chosen the best solution for my situation.

j

--
Joshua Kugler
Lead System Admin -- Senior Programmer
http://www.eeinternet.com
PGP Key: http://pgp.mit.edu/ Â*ID 0xDB26D7CE

--
Posted via a free Usenet account from http://www.teranews.com

Mar 7 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Olivier Hoarau | last post by:
Hello, I have build a client/server application with the socket module. The server mades UDP broadcasting and the client only reads UDP broadcast messages. All work fine. Now I want to use for...
3
by: Ergin Aytac | last post by:
I'm trying to run a script written in python and have some socket connection problems. I cutted the origin script (more than 1000 lines) so it is only the part of the connection and there is no...
5
by: missiplicity | last post by:
Hi, I am newbie to Python language and am taking my baby steps. I am using Python2.4 from ActiveState on W2K. I am trying to create a simple SocketServer program. Just adding the following 2 lines...
12
by: Paul Rubin | last post by:
Let's say you have a SocketServer with the threading mix-in and you run serve_forever on it. How can you shut it down, or rather, how can it even shut itself down? Even if you use a...
3
by: Magnus Lycka | last post by:
I have a socket server like below which I want to exit when it's out of data. If I interrupt the client, I'll get a broken pipe on the server side, and after a Ctrl-C, I can restart the server...
5
by: alf | last post by:
Hi, I have one thread app using SocketServer and use server_forever() as a main loop. All works fine, but now I need certain timer checking let's say every 1 second something and stopping the...
0
by: Tomi Hautakoski | last post by:
Hello, I'm a Python newbie trying to figure out how to use SocketServer with IPv6. I would like to set up a TCPServer working like below but how to tell SocketServer I need to use AF_INET6? ...
0
by: Reid Priedhorsky | last post by:
Dear all, I have a TCP server written using SocketServer with ForkingMixIn. Servicing connections is CPU-bound and can take several seconds. I now need a way to safely tell the master process...
1
by: Okko Willeboordse | last post by:
Hello, SocketServer.ThreadingTCPServer accepts connections (clients can connect) before and after it's server_forever method is called, see below for an example. IMHO it should only accept...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.