Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
GH-106176, GH-104702: Fix reference leak when importing across multiple threads#108497
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
GH-106176, GH-104702: Fix reference leak when importing across multiple threads #108497
Uh oh!
There was an error while loading. Please reload this page.
Conversation
brettcannon commented Aug 25, 2023 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
brettcannon commented Aug 25, 2023
!buildbot .*Windows11.*Refleaks |
bedevere-bot commented Aug 25, 2023
🤖 New build scheduled with the buildbot fleet by @brettcannon for commit 50e4c5d 🤖 The command will test the builders whose names match following regular expression: The builders matched are:
|
Eclips4 commented Aug 25, 2023
This is probably what we should have done. |
brettcannon commented Aug 25, 2023
FYI the Windows 11 refleak builder has not come back yet, so the green CI is a little misleading until we can get confirmation this PR doesn't leak under Windows. |
vstinner 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.
I'm now curious if it does fix the issue.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
vstinner commented Aug 25, 2023
I'm still able to reproduce the leak in the main branch: And with this PR: this is no leak, it works! Well done @brettcannon and @Eclips4! |
vstinner 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.
LGTM since it does fix the leak :-) I left a review, feel free to address it, or ignore my remarks ;-) Thanks for fixing Windows Refleaks buildbots!
Eclips4 left a comment • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
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 to all of Victor's words.
LGTM!
(I've check it on my windows setup and this solution seems fine, refleaks are gone)
Eclips4 commented Aug 26, 2023
I would prefer to backport it to 3.12, because:
|
Eclips4 commented Aug 27, 2023 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
This also solves the #104702. |
brettcannon commented Aug 28, 2023
Thanks for the reviews and verification! I should be able to get this merged at worst by Friday, but hopefully sooner. |
brettcannon commented Aug 28, 2023
I addressed the review comments from Victor, updated against |
vstinner 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.
LGTM. Thanks for the update!
miss-islington commented Aug 29, 2023
Thanks @brettcannon for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12. |
bedevere-bot commented Aug 29, 2023
GH-108612 is a backport of this pull request to the 3.12 branch. |
…cross multiple threads (pythonGH-108497) (cherry picked from commit 5f85b44) Co-authored-by: Brett Cannon <brett@python.org>
vstinner commented Aug 29, 2023
Thanks. I took the freedom of merging your PR. It became difficult to read buildbot results these days, since there are more and more known failures. This fix should reduce the number of failed buildbots! |
vstinner commented Aug 29, 2023
Again, thanks for the fix @brettcannon and @Eclips4! |
bedevere-bot commented Aug 29, 2023
|
| # Dictionary protected by the global import lock | ||
| # For a list that can have a weakref to it. | ||
| class_List(list): | ||
| pass |
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.
FWIW, I think it would be nice to use __slots__ for this class, to reduce the size of each instance (especially since the setdefault call creates one each time, even when it isn't necessary).
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.
As in you're going to make a PR to make that change, or you're hoping someone else will open an issue on your behalf to track the idea?
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.
The latter (although not on my behalf) -- I don't know if there's a reason not to do it, and I don't have the spare cycles to dig in and find out.
Yhg1s commented Sep 18, 2023
FWIW, this does not seem to have resolved the refleak in test_import in 3.12 (see e.g. https://buildbot.python.org/all/#/builders/1125/builds/115) even though it does seem to have fixed them in main. Does anyone want to take a look at why test_import is still leaking in 3.12? |
Yhg1s commented Sep 18, 2023
Nevermind, the leak was from a different issue (still not resolved on main, but more cleverly hidden). |
When importing, import deadlock detection tracks which threads are importing which modules in a list. Prior to this change, a list was created per thread but never disposed of. Now, the list is disposed of properly using weakrefs to guarantee GC doesn't interrupt the cleanup.
Co-Authored-By: Kirill Podoprigora kirill.bast9@mail.ru
test_import.test_concurrencyleaks ref on Windows #106176