473,749 Members | 2,384 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why does SocketServer default allow_reuse_add ress = 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_reus e_address = False makes restarting a server a pain if there
were connected clients, why does SocketServer default allow_reuse_add ress
to False? It's kind of bemusing to subclass ThreadingTCPSer ver 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 5957
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_reus e_address = False makes restarting a server a pain if there
were connected clients, why does SocketServer default allow_reuse_add ress
to False? It's kind of bemusing to subclass ThreadingTCPSer ver 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...@eeinter net.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_reus e_address = False makes restarting a server a pain if there
were connected clients, why does SocketServer default allow_reuse_add ress
to False? It's kind of bemusing to subclass ThreadingTCPSer ver 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****@eeinter net.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
4168
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 the same thing the socketserver module, it's ok for the client, but I don't succeed in making work the server :-(( Here is the client (which works)
3
4407
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 functionalty but connecting to a server. I have no idea about programming with python so every hint is a present for me :) ------------------------------------ import SocketServer import os
5
2675
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 of code in the program result in the errors given below: import SocketServer print "SocketServer imported"
12
13404
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 handle_request loop instead of serve_forever, it still seems difficult: class myserver(ThreadingMixIn, TCPServer): pass server = myserver(...) server.shutdown = False while not server.shutdown: server.handle_request()
3
13914
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 again, but if I let it run out of data, and exit via handle_error as can be seen below, I will get a socket.error: (98, 'Address already in use') when I try to restart the server. (Unless I wait a minute or so, or use another port.) I feel like I'm...
5
2024
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 main loop. So questions are: -how to stop serve_forever -how to implement timers thx, alf
0
1723
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? import SocketServer import logging as l l.basicConfig(level=l.DEBUG,
0
1022
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 to update its state (by groveling in a PostgreSQL database, potentially for several seconds). How can I do this safely? I thought of two ways:
1
4492
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 connections while server_forever is running. Kind regards,
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9566
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
6800
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.