Re: socket.error: [Errno 98] Address already in use
On Mon, 20 Sep 2010 12:00:41 +1200, Lawrence D'Oliveiro wrote: However, some clients choose their own source ports. E.g. rlogin/rsh use privileged (low-numbered) ports, and you can't get the kernel to choose a random privileged port for you. But nobody uses rlogin/rsh any more, They did when the bind() and SO_REUSEADDR semantics were developed. If they were doing it now, chances are that SO_REUSEADDR would be enabled by default. and who would attach any trustworthy meaning to a connection coming from a remote low-numbered source port? If you receive a connection with a low-numbered source port and it *isn't* legitimate, then someone has got root (in which case any other authentication mechanism isn't safe either) or someone has hijacked the IP address (you do know that low-numbered ports are only meaningful for systems under your control, right?). Using a firewall rule which only allows connections from a low port on specific IP addresses certainly isn't any worse than a rule which only allows connections from any port on specific IP addresses. That's true regardless of whether the protocol includes other authentication mechanisms. If you're writing a server which listens on a known port, you *should* be using SO_REUSEADDR to avoid unnecessary delays in start-up. The kernel will automatically reject packets relating to stale connections, and your server should be accepting any new connections ASAP. That makes it sound like SO_REUSEADDR should really be a superfluous option. But it’s not. Well it is mostly superfluous. It should always be enabled for a server listening on a known port, and doesn't matter for a client which uses ephemeral ports. -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.error: [Errno 98] Address already in use
In message pan.2010.09.19.05.36.20.141...@nowhere.com, Nobody wrote: On Sun, 19 Sep 2010 12:27:08 +1200, Lawrence D'Oliveiro wrote: That's why Stevens recommends that all TCP servers use the SO_REUSEADDR socket option. I don’t think I’ve ever used that. It seems to defeat a safety mechanism which was put in for a reason. It was put in for the benefit of clients, to prevent them from selecting a port which they won't be able to use. But clients typically don’t care what port they use—they let the system pick a port for them, so this kind of option is unnecessary. -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.error: [Errno 98] Address already in use
On Sun, 19 Sep 2010 18:42:51 +1200, Lawrence D'Oliveiro wrote: That's why Stevens recommends that all TCP servers use the SO_REUSEADDR socket option. I don’t think I’ve ever used that. It seems to defeat a safety mechanism which was put in for a reason. It was put in for the benefit of clients, to prevent them from selecting a port which they won't be able to use. But clients typically don’t care what port they use—they let the system pick a port for them, so this kind of option is unnecessary. If they use an ephemeral port, the kernel won't pick a port which has any connections in the TIME_WAIT state. However, some clients choose their own source ports. E.g. rlogin/rsh use privileged (low-numbered) ports, and you can't get the kernel to choose a random privileged port for you. If you're writing a server which listens on a known port, you *should* be using SO_REUSEADDR to avoid unnecessary delays in start-up. The kernel will automatically reject packets relating to stale connections, and your server should be accepting any new connections ASAP. -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.error: [Errno 98] Address already in use
In message pan.2010.09.19.17.19.19.687...@nowhere.com, Nobody wrote: However, some clients choose their own source ports. E.g. rlogin/rsh use privileged (low-numbered) ports, and you can't get the kernel to choose a random privileged port for you. But nobody uses rlogin/rsh any more, and who would attach any trustworthy meaning to a connection coming from a remote low-numbered source port? If you're writing a server which listens on a known port, you *should* be using SO_REUSEADDR to avoid unnecessary delays in start-up. The kernel will automatically reject packets relating to stale connections, and your server should be accepting any new connections ASAP. That makes it sound like SO_REUSEADDR should really be a superfluous option. But it’s not. -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.error: [Errno 98] Address already in use
On 2010-09-18, Lawrence D'Oliveiro l...@geek-central.gen.new_zealand wrote: In message 2f830099-4264-47bc-98ee-31950412a...@q21g2000prm.googlegroups.com, cerr wrote: I get a socket error [Errno 98] Address already in use when i try to open a socket that got closed before with close(). How come close() doesn't close the socket properly? The usual case this happens is you have a client connection open at the time, that was not properly terminated. Then the TCP stack goes through a holdoff period (2 minutes, I believe it is), to make absolutely sure all packets destined for the old connection have completely disappeared off the entire Internet, before it will let you open a socket on the same port again. Even when the connection was properly terminated (from an application's POV), there's a TIME_WAIT period before the TCP stack considered the connection completely gone and will allow re-use of the port. IOW, the TIME_WAIT is actually part of the connection termination (from the TCP stack's POV), and it can takes place after the application considers the connection closed (and may have even exited): http://www.developerweb.net/forum/showthread.php?t=2941 -- Grant -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.error: [Errno 98] Address already in use
In message i72a7a$dr...@reader1.panix.com, Grant Edwards wrote: Even when the connection was properly terminated (from an application's POV), there's a TIME_WAIT period before the TCP stack considered the connection completely gone and will allow re-use of the port. I’m not so sure about that. I’ve done a bunch of development on a system recently which had a server process written in Python running on a Linux box, accepting connections from a client running under old MacOS 9 (don’t ask) which was, of course, prone to crash. If the client had shut down cleanly, then I could stop and restart the server process without any problems reopening the socket. But if I forgot to close the client, then the server would hit the “already in use” error. To deal with it, I simply put in an automatic retry at 60-second intervals until it succeeded in reopening the socket. -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.error: [Errno 98] Address already in use
On Sat, 2010-09-18, Lawrence D'Oliveiro wrote: In message 2f830099-4264-47bc-98ee-31950412a...@q21g2000prm.googlegroups.com, cerr wrote: I get a socket error [Errno 98] Address already in use when i try to open a socket that got closed before with close(). How come close() doesn't close the socket properly? The usual case this happens is you have a client connection open at the time, that was not properly terminated. Then the TCP stack goes through a holdoff period (2 minutes, I believe it is), to make absolutely sure all packets destined for the old connection have completely disappeared off the entire Internet, before it will let you open a socket on the same port again. That's why Stevens recommends that all TCP servers use the SO_REUSEADDR socket option. He also noted in his book: This scenario is one of the most frequently asked questions on Usenet. Possibly I missed something in the question, but it's worth googling for. /Jorgen -- // Jorgen Grahn grahn@ Oo o. . . \X/ snipabacken.se O o . -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.error: [Errno 98] Address already in use
In message slrni9aiqt.dlt.grahn+n...@frailea.sa.invalid, Jorgen Grahn wrote: That's why Stevens recommends that all TCP servers use the SO_REUSEADDR socket option. I don’t think I’ve ever used that. It seems to defeat a safety mechanism which was put in for a reason. -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.error: [Errno 98] Address already in use
On Sun, 19 Sep 2010 12:27:08 +1200, Lawrence D'Oliveiro wrote: That's why Stevens recommends that all TCP servers use the SO_REUSEADDR socket option. I don’t think I’ve ever used that. It seems to defeat a safety mechanism which was put in for a reason. It was put in for the benefit of clients, to prevent them from selecting a port which they won't be able to use. At the point that the program calls bind(), the kernel doesn't know whether the program will call connect() or listen() next (i.e. whether it's a client or a server). Even if you set SO_REUSEADDR, you cannot create a connection which could be confused with an existing connection, i.e. one with the same source and destination address and port (BSD allows this provided that the previous connection is closed and the initial sequence number of the new connection exceeds the final sequence number of the previous connection). For a client, re-using the port would mean that any attempt to connect to the same port and address as an existing TIME_WAIT connection will fail with EADDRINUSE, so it should choose another port. This scenario is quite likely, as a client for a particular protocol will tend to connect to a specific remote port, and often to a small set of servers. But a server often has to use a specific port, and its clients will typically connect from ephemeral ports. Even if some clients insist on trying to use a specific source port (which will fail so long as the TIME_WAIT connections exist), the server can still serve other clients. -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.error: [Errno 98] Address already in use
In message 2f830099-4264-47bc-98ee-31950412a...@q21g2000prm.googlegroups.com, cerr wrote: I get a socket error [Errno 98] Address already in use when i try to open a socket that got closed before with close(). How come close() doesn't close the socket properly? The usual case this happens is you have a client connection open at the time, that was not properly terminated. Then the TCP stack goes through a holdoff period (2 minutes, I believe it is), to make absolutely sure all packets destined for the old connection have completely disappeared off the entire Internet, before it will let you open a socket on the same port again. -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.error: [Errno 98] Address already in use
On Sep 15, 5:51 pm, jipalaciosort...@gmail.com jipalaciosort...@gmail.com wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 El 15/09/2010 20:58, Grant Edwards escribió: On 2010-09-15, cerr ron.egg...@gmail.com wrote: I get a socket error [Errno 98] Address already in use when i try to open a socket that got closed before with close(). How come close() doesn't close the socket properly? My socket code : s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((host, port)) s.listen(1) ... ... ... while loop: conn, addr = s.accept() while conn and loop: ... ... ... conn.close() At what line does the error occur? To what does the phrase open a socket refer? Have you tried the usual solution of setting the SO_REUSEADDR option on the socket before calling bind? http://www.google.com/search?q=socket+%27address+already+in+use%27 Maybe, you have any other proccess in your system using your listen port, for example apache... Nope negative, I have one process on my system only that occupies port 1514. - -- _ _ _ _ _ _ _ _ _ _ _ Jose Ignacio Palacios Ortega /_ _/ / / / _ / / _ / Telf: +34 637 058 813 / / / / / /_ / / / / / / Correo-e: jipalaciosort...@gmail.com _ / / / / / _ _ _/ / / / / Msn: jipalaciosort...@gmail.com / /_ / / / / / / / /_/ / ID firma PGP: 0x0EB87E48 \ _ _ / /_/ /_/ /_ _ _/ Huella PGP:61CC 5DA0 827B C3AB F83C 2A55 78AF B317 0EB8 7E48 -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.10 (MingW32) Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org/ iEYEARECAAYFAkyRafgACgkQeK+zFw64fkjH2wCffe4v8ho2z4d8LWaPaiJRu0OZ 4cgAniOoR70hu7UylkpgAr3JI5hxNXYP =MoYK -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.error: [Errno 98] Address already in use
On Sep 15, 11:58 am, Grant Edwards inva...@invalid.invalid wrote: On 2010-09-15, cerr ron.egg...@gmail.com wrote: I get a socket error [Errno 98] Address already in use when i try to open a socket that got closed before with close(). How come close() doesn't close the socket properly? My socket code : s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((host, port)) s.listen(1) ... ... ... while loop: conn, addr = s.accept() while conn and loop: ... ... ... conn.close() At what line does the error occur? The whole message I get looks like: Traceback (most recent call last): File ./checkGPIO.py, line 148, in module main() File ./checkGPIO.py, line 75, in main s.bind((host, port)) File string, line 1, in bind socket.error: [Errno 98] Address already in use Where line 75 contains following: s.bind((host, port)) To what does the phrase open a socket refer? create a listening socket...? Have you tried the usual solution of setting the SO_REUSEADDR option on the socket before calling bind? yep, that did it for me, thanks a lot! :) http://www.google.com/search?q=socket+%27address+already+in+use%27 Google's your friend if you can read ;) -- Grant Edwards grant.b.edwards Yow! I own seven-eighths of at all the artists in downtown gmail.com Burbank! -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.error: [Errno 98] Address already in use
Where line 75 contains following: s.bind((host, port)) As Tomas pointed out, you close conn, but you do not close the server socket 's' /Björn -- http://mail.python.org/mailman/listinfo/python-list
socket.error: [Errno 98] Address already in use
Hi There, I get a socket error [Errno 98] Address already in use when i try to open a socket that got closed before with close(). How come close() doesn't close the socket properly? My socket code : s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((host, port)) s.listen(1) ... ... ... while loop: conn, addr = s.accept() while conn and loop: ... ... ... conn.close() Shouldn't that clean it all up properly? Thanks for hints suggestions! Ron -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.error: [Errno 98] Address already in use
On Wednesday 15 September 2010, it occurred to cerr to exclaim: Hi There, I get a socket error [Errno 98] Address already in use when i try to open a socket that got closed before with close(). How come close() doesn't close the socket properly? My socket code : s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((host, port)) s.listen(1) ... ... ... while loop: conn, addr = s.accept() while conn and loop: ... ... ... conn.close() Shouldn't that clean it all up properly? `s` is still listening? -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.error: [Errno 98] Address already in use
On 2010-09-15, cerr ron.egg...@gmail.com wrote: I get a socket error [Errno 98] Address already in use when i try to open a socket that got closed before with close(). How come close() doesn't close the socket properly? My socket code : s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((host, port)) s.listen(1) ... ... ... while loop: conn, addr = s.accept() while conn and loop: ... ... ... conn.close() At what line does the error occur? To what does the phrase open a socket refer? Have you tried the usual solution of setting the SO_REUSEADDR option on the socket before calling bind? http://www.google.com/search?q=socket+%27address+already+in+use%27 -- Grant Edwards grant.b.edwardsYow! I own seven-eighths of at all the artists in downtown gmail.comBurbank! -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.error: [Errno 98] Address already in use
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 El 15/09/2010 20:58, Grant Edwards escribió: On 2010-09-15, cerr ron.egg...@gmail.com wrote: I get a socket error [Errno 98] Address already in use when i try to open a socket that got closed before with close(). How come close() doesn't close the socket properly? My socket code : s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((host, port)) s.listen(1) ... ... ... while loop: conn, addr = s.accept() while conn and loop: ... ... ... conn.close() At what line does the error occur? To what does the phrase open a socket refer? Have you tried the usual solution of setting the SO_REUSEADDR option on the socket before calling bind? http://www.google.com/search?q=socket+%27address+already+in+use%27 Maybe, you have any other proccess in your system using your listen port, for example apache... - -- _ _ _ _ _ _ _ _ _ _ _ Jose Ignacio Palacios Ortega /_ _/ / / / _ / / _ / Telf: +34 637 058 813 / / / / / /_ / / / / / / Correo-e: jipalaciosort...@gmail.com _/ / / / / _ _ _/ / / / / Msn: jipalaciosort...@gmail.com / /_ / / / / / / / /_/ / ID firma PGP: 0x0EB87E48 \ _ _ / /_/ /_/ /_ _ _/ Huella PGP:61CC 5DA0 827B C3AB F83C 2A55 78AF B317 0EB8 7E48 -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.10 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkyRafgACgkQeK+zFw64fkjH2wCffe4v8ho2z4d8LWaPaiJRu0OZ 4cgAniOoR70hu7UylkpgAr3JI5hxNXYP =MoYK -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list