]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46070: Fix asyncio initialisation guard (GH-30423)
authorErlend Egeberg Aasland <erlend.aasland@innova.no>
Fri, 7 Jan 2022 14:08:19 +0000 (15:08 +0100)
committerGitHub <noreply@github.com>
Fri, 7 Jan 2022 14:08:19 +0000 (15:08 +0100)
If init flag is set, exit successfully immediately.
If not, only set the flag after successful initialization.

Misc/NEWS.d/next/Library/2022-01-07-13-51-22.bpo-46070.-axLUW.rst [new file with mode: 0644]
Modules/_asynciomodule.c

diff --git a/Misc/NEWS.d/next/Library/2022-01-07-13-51-22.bpo-46070.-axLUW.rst b/Misc/NEWS.d/next/Library/2022-01-07-13-51-22.bpo-46070.-axLUW.rst
new file mode 100644 (file)
index 0000000..0fedc9d
--- /dev/null
@@ -0,0 +1,2 @@
+Fix possible segfault when importing the :mod:`asyncio` module from
+different sub-interpreters in parallel. Patch by Erlend E. Aasland.
index 978a1fdd0d85217bffd2328fde95e91a3be6895d..b08a7d1c024c37c5ac0cf5bd47b050fcc02d5079 100644 (file)
@@ -3318,17 +3318,14 @@ static int
 module_init(void)
 {
     PyObject *module = NULL;
+    if (module_initialized) {
+        return 0;
+    }
 
     asyncio_mod = PyImport_ImportModule("asyncio");
     if (asyncio_mod == NULL) {
         goto fail;
     }
-    if (module_initialized != 0) {
-        return 0;
-    }
-    else {
-        module_initialized = 1;
-    }
 
     current_tasks = PyDict_New();
     if (current_tasks == NULL) {
@@ -3389,6 +3386,7 @@ module_init(void)
         goto fail;
     }
 
+    module_initialized = 1;
     Py_DECREF(module);
     return 0;