mirror of https://github.com/python/cpython.git
Issue #8184: multiprocessing: On Windows, don't set SO_REUSEADDR on Connection
sockets, and set FILE_FLAG_FIRST_PIPE_INSTANCE on named pipes, to make sure two listeners can't bind to the same socket/pipe (or any existing socket/pipe).
This commit is contained in:
parent
1aa54a417d
commit
ed4a8fc095
|
@ -544,7 +544,8 @@ def Pipe(duplex=True):
|
||||||
obsize, ibsize = 0, BUFSIZE
|
obsize, ibsize = 0, BUFSIZE
|
||||||
|
|
||||||
h1 = win32.CreateNamedPipe(
|
h1 = win32.CreateNamedPipe(
|
||||||
address, openmode | win32.FILE_FLAG_OVERLAPPED,
|
address, openmode | win32.FILE_FLAG_OVERLAPPED |
|
||||||
|
win32.FILE_FLAG_FIRST_PIPE_INSTANCE,
|
||||||
win32.PIPE_TYPE_MESSAGE | win32.PIPE_READMODE_MESSAGE |
|
win32.PIPE_TYPE_MESSAGE | win32.PIPE_READMODE_MESSAGE |
|
||||||
win32.PIPE_WAIT,
|
win32.PIPE_WAIT,
|
||||||
1, obsize, ibsize, win32.NMPWAIT_WAIT_FOREVER, win32.NULL
|
1, obsize, ibsize, win32.NMPWAIT_WAIT_FOREVER, win32.NULL
|
||||||
|
@ -576,7 +577,10 @@ class SocketListener(object):
|
||||||
def __init__(self, address, family, backlog=1):
|
def __init__(self, address, family, backlog=1):
|
||||||
self._socket = socket.socket(getattr(socket, family))
|
self._socket = socket.socket(getattr(socket, family))
|
||||||
try:
|
try:
|
||||||
self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
# SO_REUSEADDR has different semantics on Windows (issue #2550).
|
||||||
|
if os.name == 'posix':
|
||||||
|
self._socket.setsockopt(socket.SOL_SOCKET,
|
||||||
|
socket.SO_REUSEADDR, 1)
|
||||||
self._socket.bind(address)
|
self._socket.bind(address)
|
||||||
self._socket.listen(backlog)
|
self._socket.listen(backlog)
|
||||||
self._address = self._socket.getsockname()
|
self._address = self._socket.getsockname()
|
||||||
|
@ -630,7 +634,8 @@ class PipeListener(object):
|
||||||
def __init__(self, address, backlog=None):
|
def __init__(self, address, backlog=None):
|
||||||
self._address = address
|
self._address = address
|
||||||
handle = win32.CreateNamedPipe(
|
handle = win32.CreateNamedPipe(
|
||||||
address, win32.PIPE_ACCESS_DUPLEX,
|
address, win32.PIPE_ACCESS_DUPLEX |
|
||||||
|
win32.FILE_FLAG_FIRST_PIPE_INSTANCE,
|
||||||
win32.PIPE_TYPE_MESSAGE | win32.PIPE_READMODE_MESSAGE |
|
win32.PIPE_TYPE_MESSAGE | win32.PIPE_READMODE_MESSAGE |
|
||||||
win32.PIPE_WAIT,
|
win32.PIPE_WAIT,
|
||||||
win32.PIPE_UNLIMITED_INSTANCES, BUFSIZE, BUFSIZE,
|
win32.PIPE_UNLIMITED_INSTANCES, BUFSIZE, BUFSIZE,
|
||||||
|
|
|
@ -1779,6 +1779,17 @@ def test_missing_fd_transfer(self):
|
||||||
self.assertRaises(RuntimeError, reduction.recv_handle, conn)
|
self.assertRaises(RuntimeError, reduction.recv_handle, conn)
|
||||||
p.join()
|
p.join()
|
||||||
|
|
||||||
|
class _TestListener(BaseTestCase):
|
||||||
|
|
||||||
|
ALLOWED_TYPES = ('processes')
|
||||||
|
|
||||||
|
def test_multiple_bind(self):
|
||||||
|
for family in self.connection.families:
|
||||||
|
l = self.connection.Listener(family=family)
|
||||||
|
self.addCleanup(l.close)
|
||||||
|
self.assertRaises(OSError, self.connection.Listener,
|
||||||
|
l.address, family)
|
||||||
|
|
||||||
class _TestListenerClient(BaseTestCase):
|
class _TestListenerClient(BaseTestCase):
|
||||||
|
|
||||||
ALLOWED_TYPES = ('processes', 'threads')
|
ALLOWED_TYPES = ('processes', 'threads')
|
||||||
|
@ -1799,6 +1810,7 @@ def test_listener_client(self):
|
||||||
self.assertEqual(conn.recv(), 'hello')
|
self.assertEqual(conn.recv(), 'hello')
|
||||||
p.join()
|
p.join()
|
||||||
l.close()
|
l.close()
|
||||||
|
|
||||||
#
|
#
|
||||||
# Test of sending connection and socket objects between processes
|
# Test of sending connection and socket objects between processes
|
||||||
#
|
#
|
||||||
|
|
|
@ -472,6 +472,11 @@ Library
|
||||||
|
|
||||||
- Issue #13846: Add time.monotonic(), monotonic clock.
|
- Issue #13846: Add time.monotonic(), monotonic clock.
|
||||||
|
|
||||||
|
- Issue #8184: multiprocessing: On Windows, don't set SO_REUSEADDR on
|
||||||
|
Connection sockets, and set FILE_FLAG_FIRST_PIPE_INSTANCE on named pipes, to
|
||||||
|
make sure two listeners can't bind to the same socket/pipe (or any existing
|
||||||
|
socket/pipe).
|
||||||
|
|
||||||
- Issue #10811: Fix recursive usage of cursors. Instead of crashing,
|
- Issue #10811: Fix recursive usage of cursors. Instead of crashing,
|
||||||
raise a ProgrammingError now.
|
raise a ProgrammingError now.
|
||||||
|
|
||||||
|
|
|
@ -784,6 +784,7 @@ create_win32_namespace(void)
|
||||||
WIN32_CONSTANT(F_DWORD, ERROR_PIPE_BUSY);
|
WIN32_CONSTANT(F_DWORD, ERROR_PIPE_BUSY);
|
||||||
WIN32_CONSTANT(F_DWORD, ERROR_PIPE_CONNECTED);
|
WIN32_CONSTANT(F_DWORD, ERROR_PIPE_CONNECTED);
|
||||||
WIN32_CONSTANT(F_DWORD, ERROR_SEM_TIMEOUT);
|
WIN32_CONSTANT(F_DWORD, ERROR_SEM_TIMEOUT);
|
||||||
|
WIN32_CONSTANT(F_DWORD, FILE_FLAG_FIRST_PIPE_INSTANCE);
|
||||||
WIN32_CONSTANT(F_DWORD, FILE_FLAG_OVERLAPPED);
|
WIN32_CONSTANT(F_DWORD, FILE_FLAG_OVERLAPPED);
|
||||||
WIN32_CONSTANT(F_DWORD, GENERIC_READ);
|
WIN32_CONSTANT(F_DWORD, GENERIC_READ);
|
||||||
WIN32_CONSTANT(F_DWORD, GENERIC_WRITE);
|
WIN32_CONSTANT(F_DWORD, GENERIC_WRITE);
|
||||||
|
|
Loading…
Reference in New Issue