[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 686ec17f50)

Co-authored-by: Miguel Brito <5544985+miguendes@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2024-02-27 17:13:53 +01:00 committed by GitHub
parent 96f98d9777
commit 3af945fbb4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 1 deletions

View file

@ -476,8 +476,9 @@ class Listener(object):
''' '''
if self._listener is None: if self._listener is None:
raise OSError('listener is closed') raise OSError('listener is closed')
c = self._listener.accept() c = self._listener.accept()
if self._authkey: if self._authkey is not None:
deliver_challenge(c, self._authkey) deliver_challenge(c, self._authkey)
answer_challenge(c, self._authkey) answer_challenge(c, self._authkey)
return c return c

View file

@ -3466,6 +3466,25 @@ class _TestListener(BaseTestCase):
if self.TYPE == 'processes': if self.TYPE == 'processes':
self.assertRaises(OSError, l.accept) 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, @unittest.skipUnless(util.abstract_sockets_supported,
"test needs abstract socket support") "test needs abstract socket support")
def test_abstract_socket(self): def test_abstract_socket(self):

View file

@ -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.