[Python-checkins] bpo-33623: Fix possible SIGSGV when asyncio.Future is created in __del__ (GH-7080)

Miss Islington (bot) webhook-mailer at python.org
Mon May 28 11:28:15 EDT 2018


https://github.com/python/cpython/commit/51d0a2c8ddcb9f58d71ff0a62be4e31a1af3f139
commit: 51d0a2c8ddcb9f58d71ff0a62be4e31a1af3f139
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-05-28T08:28:12-07:00
summary:

bpo-33623: Fix possible SIGSGV when asyncio.Future is created in __del__ (GH-7080)

(cherry picked from commit 35230d08e09de4e2e52658d5cb09e5b0ca965418)

Co-authored-by: Yury Selivanov <yury at magic.io>

files:
A Misc/NEWS.d/next/Library/2018-05-23-14-58-05.bpo-33623.wAw1cF.rst
M Modules/_asynciomodule.c

diff --git a/Misc/NEWS.d/next/Library/2018-05-23-14-58-05.bpo-33623.wAw1cF.rst b/Misc/NEWS.d/next/Library/2018-05-23-14-58-05.bpo-33623.wAw1cF.rst
new file mode 100644
index 000000000000..641874c3ca39
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-05-23-14-58-05.bpo-33623.wAw1cF.rst
@@ -0,0 +1 @@
+Fix possible SIGSGV when asyncio.Future is created in __del__
diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c
index 6d7249a58009..c4d19034ce45 100644
--- a/Modules/_asynciomodule.c
+++ b/Modules/_asynciomodule.c
@@ -501,7 +501,13 @@ future_init(FutureObj *fut, PyObject *loop)
     if (is_true < 0) {
         return -1;
     }
-    if (is_true) {
+    if (is_true && !_Py_IsFinalizing()) {
+        /* Only try to capture the traceback if the interpreter is not being
+           finalized.  The original motivation to add a `_Py_IsFinalizing()`
+           call was to prevent SIGSEGV when a Future is created in a __del__
+           method, which is called during the interpreter shutdown and the
+           traceback module is already unloaded.
+        */
         fut->fut_source_tb = _PyObject_CallNoArg(traceback_extract_stack);
         if (fut->fut_source_tb == NULL) {
             return -1;



More information about the Python-checkins mailing list