Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-43952: Fix multiprocessing Listener authkey bug #25845

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Lib/multiprocessing/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,9 @@ def accept(self):
'''
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
Expand Down
19 changes: 19 additions & 0 deletions Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3504,6 +3504,25 @@ def test_context(self):
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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Loading