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. |
Sorry, something went wrong.
|
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). |
Sorry, something went wrong.
|
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 |
Sorry, something went wrong.
vstinner
left a comment
There was a problem hiding this comment.
LGTM.
Sorry, something went wrong.
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! |
Sorry, something went wrong.
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. |
Sorry, something went wrong.
Sure, I'll try to write something sensible :) Also, we could probably use a more compact version of your reproducer as a regression test. |
Sorry, something went wrong.
|
Adding a test is optional for me. It's up to me. But I would like to see a NEWS entry please. |
Sorry, something went wrong.
You got it 🥁 |
Sorry, something went wrong.
vstinner
left a comment
There was a problem hiding this comment.
LGTM.
Sorry, something went wrong.
|
Thanks @erlend-aasland for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10. |
Sorry, something went wrong.
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 <erlend.aasland@innova.no>
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 <erlend.aasland@innova.no>
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