Author trent
Recipients trent
Date 2008-04-06.21:21:01
SpamBayes Score 0.0264377
Marked as misclassified No
Message-id <>
[Updating issue with mailing list discussion; Jean-Paul's reply]
On Fri, 4 Apr 2008 13:24:49 -0700, Trent Nelson <> 
>Interesting results!  I committed the patch to in 
r62152.  I was expecting all other platforms except for Windows to 
behave consistently (i.e. pass).  That is, given the following:
>        import socket
>        host = ''
>        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>        sock.bind((host, 0))
>        port = sock.getsockname()[1]
>        sock.close()
>        del sock
>        sock1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>        sock1.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
>        sock1.bind((host, port))
>        sock2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>        sock2.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
>        sock2.bind((host, port))
>        ^^^^
>....the second bind should fail with EADDRINUSE, at least according to 
the 'SO_REUSEADDR and SO_REUSEPORT Socket Options' section in chapter 
7.5 of Stevens' UNIX Network Programming Volume 1 (2nd Ed):
>"With TCP, we are never able to start multiple servers that bind
> the same IP address and same port: a completely duplicate binding.
> That is, we cannot start one server that binds port 80
> and start another that also binds port 80, even if we
> set the SO_REUSEADDR socket option for the second server."
>The results: both Windows *and* Linux fail the patched test; none of 
the buildbots for either platform encountered an EADDRINUSE 
socket.error after the second bind().  FreeBSD, OS X, Solaris and Tru64 
pass the test -- EADDRINUSE is raised on the second bind.  (Interesting 
that all the ones that passed have a BSD lineage.)

Notice that the quoted text explains that you cannot start multiple 
that etc.  Since you didn't call listen on either socket, it's arguable 
you didn't start any servers, so there should be no surprise regarding 
behavior.  Try adding listen calls at various places in the example and
you'll see something different happen.

FWIW, AIUI, SO_REUSEADDR behaves just as described in the above quote on
Linux/BSD/UNIX/etc.  On Windows, however, that option actually means
something quite different.  It means that the address should be stolen 
any process which happens to be using it at the moment.

There is another option, SO_EXCLUSIVEADDRUSE, only on Windows I think,
which, AIUI, makes it impossible for another process to steal the port

Hope this helps,

Date User Action Args
2008-04-06 21:21:04trentsetspambayes_score: 0.0264377 -> 0.0264377
recipients: + trent
2008-04-06 21:21:03trentsetspambayes_score: 0.0264377 -> 0.0264377
messageid: <>
2008-04-06 21:21:02trentlinkissue2550 messages
2008-04-06 21:21:01trentcreate