]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-43952: Fix multiprocessing Listener authkey bug (GH-25845)
authorMiguel Brito <5544985+miguendes@users.noreply.github.com>
Tue, 27 Feb 2024 14:57:59 +0000 (14:57 +0000)
committerGitHub <noreply@github.com>
Tue, 27 Feb 2024 14:57:59 +0000 (14:57 +0000)
Listener.accept() no longer hangs when authkey is an empty bytes object.

Lib/multiprocessing/connection.py
Lib/test/_test_multiprocessing.py
Misc/NEWS.d/next/Library/2021-05-03-11-04-12.bpo-43952.Me7fJe.rst [new file with mode: 0644]

index 58d697fdecacc05750535e65b660299f9c6bfcab..b7e1e132172d0203d9f584854a7bc7b30aa08bd0 100644 (file)
@@ -476,8 +476,9 @@ class Listener(object):
         '''
         if self._listener is None:
             raise OSError('listener is closed')
+
         c = self._listener.accept()
-        if self._authkey:
+        if self._authkey is not None:
             deliver_challenge(c, self._authkey)
             answer_challenge(c, self._authkey)
         return c
index f70a693e641b4e70e859d08ce57de5182211daf3..058537bab5af260e95a0505f6c221eb7f40e621d 100644 (file)
@@ -3504,6 +3504,25 @@ class _TestListener(BaseTestCase):
         if self.TYPE == 'processes':
             self.assertRaises(OSError, l.accept)
 
+    def test_empty_authkey(self):
+        # bpo-43952: allow empty bytes as authkey
+        def handler(*args):
+            raise RuntimeError('Connection took too long...')
+
+        def run(addr, authkey):
+            client = self.connection.Client(addr, authkey=authkey)
+            client.send(1729)
+
+        key = b""
+
+        with self.connection.Listener(authkey=key) as listener:
+            threading.Thread(target=run, args=(listener.address, key)).start()
+            with listener.accept() as d:
+                self.assertEqual(d.recv(), 1729)
+
+        if self.TYPE == 'processes':
+            self.assertRaises(OSError, listener.accept)
+
     @unittest.skipUnless(util.abstract_sockets_supported,
                          "test needs abstract socket support")
     def test_abstract_socket(self):
diff --git a/Misc/NEWS.d/next/Library/2021-05-03-11-04-12.bpo-43952.Me7fJe.rst b/Misc/NEWS.d/next/Library/2021-05-03-11-04-12.bpo-43952.Me7fJe.rst
new file mode 100644 (file)
index 0000000..e164619
--- /dev/null
@@ -0,0 +1,2 @@
+Fix :meth:`multiprocessing.connection.Listener.accept()` to accept empty bytes
+as authkey. Not accepting empty bytes as key causes it to hang indefinitely.