-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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-46070: Fix asyncio initialisation guard #30423
Conversation
If init flag is set, exit successfully immediately. If not, only set the flag after successful initialisation.
Maybe we should run this through the buildbots. |
This might qualify for a NEWS entry, as it fixes segfaults on 3.10 and 3.9 (and 3.8, but 3.8 is in security-fix-mode-only). |
module_init() is called in parallel multiple times from different interpreters (in different threads). I understand that module_init() leaks references when calling multiple times in parallel, since it doesn't use |
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.
Yes, there are ref leaks, but as you say they are best fixed by converting global state to module state and implement proper multi-phase init. I've got a private branch for this work. This demands a separate bpo issue, and we should involve the asyncio maintaner before continuing with that effort :) Thanks for reviewing! |
Oh, I didn't notice the failing "news" job. Yes, please document the fix. If I understand correctly, this change fix a crash an importing the asyncio module from different sub-interpreters in parallel. And the workaround was to import asyncio in the main interpreter before spawning sub-interpreters. |
Sure, I'll try to write something sensible :) Also, we could probably use a more compact version of your reproducer as a regression test. |
Adding a test is optional for me. It's up to me. But I would like to see a NEWS entry please. |
You got it 🥁 |
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 @erlend-aasland for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10. |
If init flag is set, exit successfully immediately. If not, only set the flag after successful initialization. (cherry picked from commit b127e70) Co-authored-by: Erlend Egeberg Aasland <[email protected]>
GH-30453 is a backport of this pull request to the 3.10 branch. |
If init flag is set, exit successfully immediately. If not, only set the flag after successful initialization. (cherry picked from commit b127e70) Co-authored-by: Erlend Egeberg Aasland <[email protected]>
GH-30454 is a backport of this pull request to the 3.9 branch. |
If init flag is set, exit successfully immediately. If not, only set the flag after successful initialization. (cherry picked from commit b127e70) Co-authored-by: Erlend Egeberg Aasland <[email protected]>
If init flag is set, exit successfully immediately. If not, only set the flag after successful initialization. (cherry picked from commit b127e70) Co-authored-by: Erlend Egeberg Aasland <[email protected]>
If init flag is set, exit module init successfully immediately.
If not, only set the flag after successful module initialisation.
https://bugs.python.org/issue46070