-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
gh-90549: Fix leak of global named resources using multiprocessing spawn #30617
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
Conversation
|
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). CLA MissingOur records indicate the following people have not signed the CLA: For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. If you have recently signed the CLA, please wait at least one business day You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
3aef095 to
055a4c2
Compare
fa9d895 to
dd3fca1
Compare
|
cc @pitrou |
|
Could you merge a fresh |
OK. I've rebased the patch to the |
@arhadthedev Hope for review and fix. The problem caused by this bug is really annoying. A warning appears on most of the repo commands I use. #90549 |
pitrou
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for diagnosing this and finding a fix! Here are a couple comments.
|
🤖 New build scheduled with the buildbot fleet by @pitrou for commit 11b3674851836dfc0cd1a1817e26b625a95bb32b 🤖 If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again. |
pitrou
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, thanks a lot @jxdabc .
|
Let's wait a bit for the buildbot results now. |
|
We might want to backport this to 3.10, given that this fixes a leak. |
@pitrou what I need to do about this backport? |
|
@jxdabc Nothing special, it's a decision core developers make. @vstinner @pablogsal What do you think? |
|
It's a bugfix, it should be backported.
That's right, but if it introduces a regression, it can be fixed as well. |
@pitrou Glad to see all check passed. |
|
GH-93651 is a backport of this pull request to the 3.11 branch. |
|
GH-93652 is a backport of this pull request to the 3.10 branch. |
Repo is the standard tool that Google uses to build Android, Chrome OS, Chromium, etc, written in Python.
Many Repo users have encountered resource leak warnings with Python 3.9.
https://bugs.chromium.org/p/gerrit/issues/detail?id=14934&q=component%3Arepo&can=5
I did some work and found that the problem is not caused by the code of Repo, but a bug of the Python library, multiprocess.
To make it simple, the Python script below leaks named resource even when exiting normally. (And be unlinked by resource_tracker with a warning. )
Tested on macOS with Python 3.9.7
This bug will 100% reproduce when then main module uses named resources as global variables and uses
spawncontext, which is the case of Repo on macOS.This is caused by multiprocess::BaseProcess::_bootstrap.
When a new process is started with multiprocessing.Process.start() in
spawncontext.When a subprocess is spawned, it is no need to clear util::_finalizer_registry (and no need to call util::_run_after_forkers). Disable clearing _finalizer_registry (and disable call to _run_after_forkers) should fix this bug without breaking anything else.
And I uploaded a MR.
https://bugs.python.org/issue46391