mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
Issue #14669: Fix pickling of connections and sockets on MacOSX
by sending/receiving an acknowledgment after file descriptor transfer. TestPicklingConnection has been reenabled for MacOSX.
This commit is contained in:
parent
69a06dd59d
commit
04ec8ce1bb
3 changed files with 12 additions and 2 deletions
|
@ -120,16 +120,24 @@ if sys.platform == 'win32':
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Unix
|
# Unix
|
||||||
|
|
||||||
|
# On MacOSX we should acknowledge receipt of fds -- see Issue14669
|
||||||
|
ACKNOWLEDGE = sys.platform == 'darwin'
|
||||||
|
|
||||||
def send_handle(conn, handle, destination_pid):
|
def send_handle(conn, handle, destination_pid):
|
||||||
with socket.fromfd(conn.fileno(), socket.AF_UNIX, socket.SOCK_STREAM) as s:
|
with socket.fromfd(conn.fileno(), socket.AF_UNIX, socket.SOCK_STREAM) as s:
|
||||||
s.sendmsg([b'x'], [(socket.SOL_SOCKET, socket.SCM_RIGHTS,
|
s.sendmsg([b'x'], [(socket.SOL_SOCKET, socket.SCM_RIGHTS,
|
||||||
struct.pack("@i", handle))])
|
struct.pack("@i", handle))])
|
||||||
|
if ACKNOWLEDGE and conn.recv_bytes() != b'ACK':
|
||||||
|
raise RuntimeError('did not receive acknowledgement of fd')
|
||||||
|
|
||||||
def recv_handle(conn):
|
def recv_handle(conn):
|
||||||
size = struct.calcsize("@i")
|
size = struct.calcsize("@i")
|
||||||
with socket.fromfd(conn.fileno(), socket.AF_UNIX, socket.SOCK_STREAM) as s:
|
with socket.fromfd(conn.fileno(), socket.AF_UNIX, socket.SOCK_STREAM) as s:
|
||||||
msg, ancdata, flags, addr = s.recvmsg(1, socket.CMSG_LEN(size))
|
msg, ancdata, flags, addr = s.recvmsg(1, socket.CMSG_LEN(size))
|
||||||
try:
|
try:
|
||||||
|
if ACKNOWLEDGE:
|
||||||
|
conn.send_bytes(b'ACK')
|
||||||
cmsg_level, cmsg_type, cmsg_data = ancdata[0]
|
cmsg_level, cmsg_type, cmsg_data = ancdata[0]
|
||||||
if (cmsg_level == socket.SOL_SOCKET and
|
if (cmsg_level == socket.SOL_SOCKET and
|
||||||
cmsg_type == socket.SCM_RIGHTS):
|
cmsg_type == socket.SCM_RIGHTS):
|
||||||
|
|
|
@ -2446,8 +2446,6 @@ class _TestPoll(unittest.TestCase):
|
||||||
# Test of sending connection and socket objects between processes
|
# Test of sending connection and socket objects between processes
|
||||||
#
|
#
|
||||||
|
|
||||||
# Intermittent fails on Mac OS X -- see Issue14669 and Issue12958
|
|
||||||
@unittest.skipIf(sys.platform == "darwin", "fd passing unreliable on Mac OS X")
|
|
||||||
@unittest.skipUnless(HAS_REDUCTION, "test needs multiprocessing.reduction")
|
@unittest.skipUnless(HAS_REDUCTION, "test needs multiprocessing.reduction")
|
||||||
class _TestPicklingConnections(BaseTestCase):
|
class _TestPicklingConnections(BaseTestCase):
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,10 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #14669: Fix pickling of connections and sockets on MacOSX
|
||||||
|
by sending/receiving an acknowledgment after file descriptor transfer.
|
||||||
|
TestPicklingConnection has been reenabled for MacOSX.
|
||||||
|
|
||||||
- Issue #11062: Fix adding a message from file to Babyl mailbox.
|
- Issue #11062: Fix adding a message from file to Babyl mailbox.
|
||||||
|
|
||||||
- Issue #15646: Prevent equivalent of a fork bomb when using
|
- Issue #15646: Prevent equivalent of a fork bomb when using
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue