mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
Revert r62152 (Issue #2550). Being able to observe the results of all the buildbots was certainly useful. All of the platforms that have some form of BSD lineage -- FreeBSD, OS X, Solaris and Tru64 -- all pass the test. Windows and Linux, on the other hand, don't. Windows I knew about, Linux was a surprise. Knowing this, I believe a more appropriate fix will revolve around test_support.bind_socket() -- this method needs to return a port that nothing in the system has bound already. The best way to do this may just be to rely on ephemeral ports, rather than having the user specify a desired port, then fall back to four random ports, then try 0.
This commit is contained in:
parent
f790648c8c
commit
4bffe8293f
1 changed files with 0 additions and 76 deletions
|
@ -3,7 +3,6 @@
|
|||
import unittest
|
||||
from test import test_support
|
||||
|
||||
import errno
|
||||
import socket
|
||||
import select
|
||||
import thread, threading
|
||||
|
@ -487,81 +486,6 @@ class GeneralModuleTests(unittest.TestCase):
|
|||
reuse = sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR)
|
||||
self.failIf(reuse == 0, "failed to set reuse mode")
|
||||
|
||||
def testAddressReuseSemantics(self):
|
||||
# As per 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 198.69.10.2 port 80
|
||||
# and start another that also binds 198.69.10.2 port 80, even if we
|
||||
# set the SO_REUSEADDR socket option for the second server."
|
||||
#
|
||||
# However, on Windows, it seems that if SO_REUSEADDR is set on the 2nd
|
||||
# socket, binding to an already bound (host, port) combination doesn't
|
||||
# raise an exception. Instead, it causes Python to wedge pretty badly
|
||||
# when accept() is called against either of the sockets. This test case
|
||||
# is being added to help debug this issue, as well as seeing if the
|
||||
# expected semantics differ on any other platforms.
|
||||
|
||||
# Get a port that we *know* is unique. Don't rely on test_support's
|
||||
# bind_port method, as this operates under the assumption that an
|
||||
# EADDRINUSE exception will be raised correctly, which is exactly what
|
||||
# we're trying to test here.
|
||||
host = '127.0.0.1'
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.bind((host, 0))
|
||||
port = sock.getsockname()[1]
|
||||
sock.close()
|
||||
del sock
|
||||
|
||||
# First test that we get EADDRINUSE without SO_REUSEADDR.
|
||||
sock1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock1.bind((host, port))
|
||||
sock2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
try:
|
||||
sock2.bind((host, port))
|
||||
except socket.error, (err, msg):
|
||||
self.assertEqual(err, errno.EADDRINUSE)
|
||||
else:
|
||||
self.fail("expected EADDRINUSE socket.error exception to be " \
|
||||
"raised when attempting to bind a second socket to " \
|
||||
"a (host, port) we've already bound to (SO_REUSEADDR " \
|
||||
"was NOT set on the socket)")
|
||||
finally:
|
||||
sock1.close()
|
||||
try:
|
||||
sock2.close()
|
||||
except:
|
||||
pass
|
||||
del sock1
|
||||
del sock2
|
||||
|
||||
# Try again with SO_REUSEADDR; the behaviour *should* be identical to
|
||||
# the test above, i.e. an EADDRINUSE socket.error should be raised.
|
||||
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)
|
||||
try:
|
||||
sock2.bind((host, port))
|
||||
except socket.error, (err, msg):
|
||||
self.assertEqual(err, errno.EADDRINUSE)
|
||||
else:
|
||||
self.fail("expected EADDRINUSE socket.error exception to be " \
|
||||
"raised when attempting to bind a second socket to " \
|
||||
"a (host, port) we've already bound to (SO_REUSEADDR " \
|
||||
"*WAS* set on the socket)")
|
||||
finally:
|
||||
sock1.close()
|
||||
try:
|
||||
sock2.close()
|
||||
except:
|
||||
pass
|
||||
del sock1
|
||||
del sock2
|
||||
|
||||
def testSendAfterClose(self):
|
||||
# testing send() after close() with timeout
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue