Skip to content

Commit 3e7832a

Browse files
miguendesadorilson
authored andcommitted
bpo-43952: Fix multiprocessing Listener authkey bug (pythonGH-25845)
Listener.accept() no longer hangs when authkey is an empty bytes object.
1 parent 7bcef57 commit 3e7832a

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
@@ -3504,6 +3504,25 @@ def test_context(self):
35043504
if self.TYPE == 'processes':
35053505
self.assertRaises(OSError, l.accept)
35063506

3507+
def test_empty_authkey(self):
3508+
# bpo-43952: allow empty bytes as authkey
3509+
def handler(*args):
3510+
raise RuntimeError('Connection took too long...')
3511+
3512+
def run(addr, authkey):
3513+
client = self.connection.Client(addr, authkey=authkey)
3514+
client.send(1729)
3515+
3516+
key = b""
3517+
3518+
with self.connection.Listener(authkey=key) as listener:
3519+
threading.Thread(target=run, args=(listener.address, key)).start()
3520+
with listener.accept() as d:
3521+
self.assertEqual(d.recv(), 1729)
3522+
3523+
if self.TYPE == 'processes':
3524+
self.assertRaises(OSError, listener.accept)
3525+
35073526
@unittest.skipUnless(util.abstract_sockets_supported,
35083527
"test needs abstract socket support")
35093528
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)