[Python-checkins] cpython: Issue #14669: Fix pickling of connections and sockets on MacOSX

richard.oudkerk python-checkins at python.org
Thu Aug 16 17:51:21 CEST 2012


http://hg.python.org/cpython/rev/4307b985209b
changeset:   78610:4307b985209b
user:        Richard Oudkerk <shibturn at gmail.com>
date:        Thu Aug 16 16:48:55 2012 +0100
summary:
  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.

files:
  Lib/multiprocessing/reduction.py |  8 ++++++++
  Lib/test/test_multiprocessing.py |  2 --
  Misc/NEWS                        |  4 ++++
  3 files changed, 12 insertions(+), 2 deletions(-)


diff --git a/Lib/multiprocessing/reduction.py b/Lib/multiprocessing/reduction.py
--- a/Lib/multiprocessing/reduction.py
+++ b/Lib/multiprocessing/reduction.py
@@ -120,16 +120,24 @@
 
 else:
     # Unix
+
+    # On MacOSX we should acknowledge receipt of fds -- see Issue14669
+    ACKNOWLEDGE = sys.platform == 'darwin'
+
     def send_handle(conn, handle, destination_pid):
         with socket.fromfd(conn.fileno(), socket.AF_UNIX, socket.SOCK_STREAM) as s:
             s.sendmsg([b'x'], [(socket.SOL_SOCKET, socket.SCM_RIGHTS,
                                 struct.pack("@i", handle))])
+        if ACKNOWLEDGE and conn.recv_bytes() != b'ACK':
+            raise RuntimeError('did not receive acknowledgement of fd')
 
     def recv_handle(conn):
         size = struct.calcsize("@i")
         with socket.fromfd(conn.fileno(), socket.AF_UNIX, socket.SOCK_STREAM) as s:
             msg, ancdata, flags, addr = s.recvmsg(1, socket.CMSG_LEN(size))
             try:
+                if ACKNOWLEDGE:
+                    conn.send_bytes(b'ACK')
                 cmsg_level, cmsg_type, cmsg_data = ancdata[0]
                 if (cmsg_level == socket.SOL_SOCKET and
                     cmsg_type == socket.SCM_RIGHTS):
diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py
--- a/Lib/test/test_multiprocessing.py
+++ b/Lib/test/test_multiprocessing.py
@@ -2446,8 +2446,6 @@
 # Test of sending connection and socket objects between processes
 #
 
-# Intermittent fails on Mac OS X -- see Issue14669 and Issue12958
- at unittest.skipIf(sys.platform == "darwin", "fd passing unreliable on Mac OS X")
 @unittest.skipUnless(HAS_REDUCTION, "test needs multiprocessing.reduction")
 class _TestPicklingConnections(BaseTestCase):
 
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -16,6 +16,10 @@
 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 #15646: Prevent equivalent of a fork bomb when using

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list