summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-02-27 16:13:53 (GMT)
committerGitHub <noreply@github.com>2024-02-27 16:13:53 (GMT)
commit3af945fbb47600077850dc7fbcdbc323ddd83dd5 (patch)
tree20e0644a53d4cbb29f156681526cddfb02b6df46
parent96f98d97776992096ad8d4d07e8acf2dfb7ff71c (diff)
downloadcpython-3af945fbb47600077850dc7fbcdbc323ddd83dd5.zip
cpython-3af945fbb47600077850dc7fbcdbc323ddd83dd5.tar.gz
cpython-3af945fbb47600077850dc7fbcdbc323ddd83dd5.tar.bz2
[3.12] bpo-43952: Fix multiprocessing Listener authkey bug (GH-25845) (GH-115995)
Listener.accept() no longer hangs when authkey is an empty bytes object. (cherry picked from commit 686ec17f506cddd0b14a8aad5849c15ffc20ed46) Co-authored-by: Miguel Brito <5544985+miguendes@users.noreply.github.com>
-rw-r--r--Lib/multiprocessing/connection.py3
-rw-r--r--Lib/test/_test_multiprocessing.py19
-rw-r--r--Misc/NEWS.d/next/Library/2021-05-03-11-04-12.bpo-43952.Me7fJe.rst2
3 files changed, 23 insertions, 1 deletions
diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py
index dbbf106..d0582e3 100644
--- a/Lib/multiprocessing/connection.py
+++ b/Lib/multiprocessing/connection.py
@@ -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
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py
index 889ebb8..54ee93a 100644
--- a/Lib/test/_test_multiprocessing.py
+++ b/Lib/test/_test_multiprocessing.py
@@ -3466,6 +3466,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
index 0000000..e164619
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-05-03-11-04-12.bpo-43952.Me7fJe.rst
@@ -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.