Author neologix
Recipients BreamoreBoy, gearb0x, jnoller, neologix, news1234, pitrou
Date 2012-01-08.19:42:13
SpamBayes Score 3.12146e-11
Marked as misclassified No
Message-id <1326051794.53.0.921653759311.issue8184@psf.upfronthosting.co.za>
In-reply-to
Content
Here's a patch addressing the multiple bind() problem on Windows.

Note that this problem also affects other parts of the stdlib, which use SO_REUSEADDR when available.

Also, there's an rather confusing comment in support.find_unused_port():

"""
    (This is easy to reproduce on Windows, unfortunately, and can be traced to
    the SO_REUSEADDR socket option having different semantics on Windows versus
    Unix/Linux.  On Unix, you can't have two AF_INET SOCK_STREAM sockets bind,
    listen and then accept connections on identical host/ports.  An EADDRINUSE
    socket.error will be raised at some point (depending on the platform and
    the order bind and listen were called on each socket).

    However, on Windows, if SO_REUSEADDR is set on the sockets, no EADDRINUSE
    will ever be raised when attempting to bind two identical host/ports. When
    accept() is called on each socket, the second caller's process will steal
    the port from the first caller, leaving them both in an awkwardly wedged
    state where they'll no longer respond to any signals or graceful kills, and
    must be forcibly killed via OpenProcess()/TerminateProcess().

    The solution on Windows is to use the SO_EXCLUSIVEADDRUSE socket option
    instead of SO_REUSEADDR, which effectively affords the same semantics as
    SO_REUSEADDR on Unix.  Given the propensity of Unix developers in the Open
    Source world compared to Windows ones, this is a common mistake.  A quick
    look over OpenSSL's 0.9.8g source shows that they use SO_REUSEADDR when
    openssl.exe is called with the 's_server' option, for example. See
    http://bugs.python.org/issue2550 for more info.  The following site also
    has a very thorough description about the implications of both REUSEADDR
    and EXCLUSIVEADDRUSE on Windows:
    http://msdn2.microsoft.com/en-us/library/ms740621(VS.85).aspx)
"""

I have no idea why it uses SO_REUSEADDR + SO_EXCLUSIVEADDRUSE instead of just keeping the default setting, since we don't want to allow multiple bind(), but bypass the TIME-WAIT lingering.
History
Date User Action Args
2012-01-08 19:43:14neologixsetrecipients: + neologix, pitrou, jnoller, news1234, BreamoreBoy, gearb0x
2012-01-08 19:43:14neologixsetmessageid: <1326051794.53.0.921653759311.issue8184@psf.upfronthosting.co.za>
2012-01-08 19:42:14neologixlinkissue8184 messages
2012-01-08 19:42:13neologixcreate