Skip to content

gh-101225: Fix hang when passing Pipe instances to child in multiprocessing#113567

Merged
ronaldoussoren merged 5 commits into
python:mainfrom
ronaldoussoren:gh-101225
Jan 13, 2024
Merged

gh-101225: Fix hang when passing Pipe instances to child in multiprocessing#113567
ronaldoussoren merged 5 commits into
python:mainfrom
ronaldoussoren:gh-101225

Conversation

@ronaldoussoren

@ronaldoussoren ronaldoussoren commented Dec 29, 2023

Copy link
Copy Markdown
Contributor

This PR uses the same backlog value when creating
a .connection.Client in .resource_sharer as is used in .manager.

On macOS the default backlog (1) is small enough to cause the socket accept queue to fill up when starting a number of children.

…tiprocessing

This PR uses the same backlog value when creating
a `.connection.Client` in `.resource_sharer` as is used in
`.manager`.

On macOS the default backlog (1) is small enough to cause the
socket accept queue to fill up when starting a number of children.
@ronaldoussoren

Copy link
Copy Markdown
Contributor Author

Is there any reason to keep the backlog value at 16? Increasing the backlog at both locations (this one and the one in manager.py) to 64 would fix #87934 on my laptop.

@ronaldoussoren

Copy link
Copy Markdown
Contributor Author

I've increased the backlog parameter in both manager.py and resource_sharer.py. As mentioned in my previous message this will also fix #87934.

@gpshead gpshead left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no problem with this change, we may as well have a larger listen queue - systems are large enough these days... but I'm wary of calling it a "fix". It feels like this just papers over the problem and leaves it to reappear later as machines grow, or perhaps under heavy system load.

If something can hang due to a connection failure not being to a retry rather than losing track of the task it was supposed to accomplish (if the bug report summary is accurate)... the real bug lurks there, rather than just the queue depth?

@ronaldoussoren

Copy link
Copy Markdown
Contributor Author

I have no problem with this change, we may as well have a larger listen queue - systems are large enough these days... but I'm wary of calling it a "fix". It feels like this just papers over the problem and leaves it to reappear later as machines grow, or perhaps under heavy system load.

If something can hang due to a connection failure not being to a retry rather than losing track of the task it was supposed to accomplish (if the bug report summary is accurate)... the real bug lurks there, rather than just the queue depth?

Yeah, I'm being a bit optimistic here. There is a race condition between the processes creating connections and the proces waiting for connections. To be honest I don't understand why a backlog of 1 in resource_sharer causes problems on macOS but not on other platforms.

In #87934 I added a retry loop that also fixes the issue (for manager). That patch (in #87934 (comment)) is a crude hack, and can still fail if the server end of the connection is too slow. That patch also adds a couple of tuneables where I don't know what good values would be (number of retries and wait time between retries, possibly even some for of scaled back-off).

@ronaldoussoren

Copy link
Copy Markdown
Contributor Author

I've updated the new entry, it is now clearer about what changed and no longer claims this definitely fixes something.

Comment thread Misc/NEWS.d/next/Library/2023-12-29-17-46-06.gh-issue-101225.QaEyxF.rst Outdated
@ronaldoussoren
ronaldoussoren merged commit c7d59bd into python:main Jan 13, 2024
@miss-islington-app

Copy link
Copy Markdown

Thanks @ronaldoussoren for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@ronaldoussoren
ronaldoussoren deleted the gh-101225 branch January 13, 2024 09:48
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 13, 2024
…cessing.connection.Listener (pythonGH-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.
(cherry picked from commit c7d59bd)

Co-authored-by: Ronald Oussoren <ronaldoussoren@mac.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 13, 2024
…cessing.connection.Listener (pythonGH-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.
(cherry picked from commit c7d59bd)

Co-authored-by: Ronald Oussoren <ronaldoussoren@mac.com>
@bedevere-app

bedevere-app Bot commented Jan 13, 2024

Copy link
Copy Markdown

GH-114018 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.12 only security fixes label Jan 13, 2024
@bedevere-app

bedevere-app Bot commented Jan 13, 2024

Copy link
Copy Markdown

GH-114019 is a backport of this pull request to the 3.11 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.11 only security fixes label Jan 13, 2024
ronaldoussoren added a commit that referenced this pull request Jan 14, 2024
…ocessing.connection.Listener (GH-113567) (#114018)

gh-101225: Increase the socket backlog when creating a multiprocessing.connection.Listener (GH-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.
(cherry picked from commit c7d59bd)

Co-authored-by: Ronald Oussoren <ronaldoussoren@mac.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
ronaldoussoren added a commit that referenced this pull request Jan 14, 2024
…ocessing.connection.Listener (GH-113567) (#114019)

gh-101225: Increase the socket backlog when creating a multiprocessing.connection.Listener (GH-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.
(cherry picked from commit c7d59bd)

Co-authored-by: Ronald Oussoren <ronaldoussoren@mac.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
kulikjak pushed a commit to kulikjak/cpython that referenced this pull request Jan 22, 2024
…cessing.connection.Listener (python#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.
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
…cessing.connection.Listener (python#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.
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
…cessing.connection.Listener (python#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants