Skip to content

Commit

Permalink
gh-101225: Increase the socket backlog when creating a multiprocessin…
Browse files Browse the repository at this point in the history
…g.connection.Listener (#113567)

Increase the backlog for multiprocessing.connection.Listener` objects created
 by `multiprocessing.manager` and `multiprocessing.resource_sharer` to
 significantly reduce the risk of getting a connection refused error when creating
 a `multiprocessing.connection.Connection` to them.
  • Loading branch information
ronaldoussoren authored Jan 13, 2024
1 parent 21f83ef commit c7d59bd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Lib/multiprocessing/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def __init__(self, registry, address, authkey, serializer):
Listener, Client = listener_client[serializer]

# do authentication later
self.listener = Listener(address=address, backlog=16)
self.listener = Listener(address=address, backlog=128)
self.address = self.listener.address

self.id_to_obj = {'0': (None, ())}
Expand Down
2 changes: 1 addition & 1 deletion Lib/multiprocessing/resource_sharer.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def _start(self):
from .connection import Listener
assert self._listener is None, "Already have Listener"
util.debug('starting listener and thread for sending handles')
self._listener = Listener(authkey=process.current_process().authkey)
self._listener = Listener(authkey=process.current_process().authkey, backlog=128)
self._address = self._listener.address
t = threading.Thread(target=self._serve)
t.daemon = True
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Increase the backlog for :class:`multiprocessing.connection.Listener` objects created
by :mod:`multiprocessing.manager` and :mod:`multiprocessing.resource_sharer` to
significantly reduce the risk of getting a connection refused error when creating
a :class:`multiprocessing.connection.Connection` to them.

0 comments on commit c7d59bd

Please sign in to comment.