Skip to content

Commit eb13ac6

Browse files
[3.11] bpo-43952: Fix multiprocessing Listener authkey bug (GH-25845) (GH-115994)
Listener.accept() no longer hangs when authkey is an empty bytes object. (cherry picked from commit 686ec17) Co-authored-by: Miguel Brito <[email protected]>
1 parent cccd73d commit eb13ac6

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

Lib/multiprocessing/connection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,9 @@ def accept(self):
476476
'''
477477
if self._listener is None:
478478
raise OSError('listener is closed')
479+
479480
c = self._listener.accept()
480-
if self._authkey:
481+
if self._authkey is not None:
481482
deliver_challenge(c, self._authkey)
482483
answer_challenge(c, self._authkey)
483484
return c

Lib/test/_test_multiprocessing.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3465,6 +3465,25 @@ def test_context(self):
34653465
if self.TYPE == 'processes':
34663466
self.assertRaises(OSError, l.accept)
34673467

3468+
def test_empty_authkey(self):
3469+
# bpo-43952: allow empty bytes as authkey
3470+
def handler(*args):
3471+
raise RuntimeError('Connection took too long...')
3472+
3473+
def run(addr, authkey):
3474+
client = self.connection.Client(addr, authkey=authkey)
3475+
client.send(1729)
3476+
3477+
key = b""
3478+
3479+
with self.connection.Listener(authkey=key) as listener:
3480+
threading.Thread(target=run, args=(listener.address, key)).start()
3481+
with listener.accept() as d:
3482+
self.assertEqual(d.recv(), 1729)
3483+
3484+
if self.TYPE == 'processes':
3485+
self.assertRaises(OSError, listener.accept)
3486+
34683487
@unittest.skipUnless(util.abstract_sockets_supported,
34693488
"test needs abstract socket support")
34703489
def test_abstract_socket(self):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix :meth:`multiprocessing.connection.Listener.accept()` to accept empty bytes
2+
as authkey. Not accepting empty bytes as key causes it to hang indefinitely.

0 commit comments

Comments
 (0)