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
Importing asyncio after deleting a coroutine object and before cleaning it up leads to crashing on Python3.11 #89971
Comments
The following crashing can only reproduce on Python3.11. In this case, we import "asyncio" after deleting a coroutine object and before cleaning it up, leading to crashing. test.py async def f():
pass
f = f()
frame = f.cr_frame
del f
import asyncio
frame.clear() ====================== >>>Python3.11 -Werror test.py
Exception ignored in: <coroutine object f at 0x7f860ad9cdd0>
Traceback (most recent call last):
File "python311/Lib/warnings.py", line 506, in _warn_unawaited_coroutine
warn(msg, category=RuntimeWarning, stacklevel=2, source=coro)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeWarning: coroutine 'f' was never awaited
Segmentation fault (core dumped) Version: Python 3.11.0a2+ on Ubuntu 16.04 |
No crash on Windows running in CommandPrompt (using -i to ensure that python survives running the test code): C:\Users\Terry>py -3.10 -i f:/dev/tem/tem.py
f:\dev\tem\tem.py:5: RuntimeWarning: coroutine 'f' was never awaited
del f
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
>>> quit()
C:\Users\Terry>py -3.11 -i f:/dev/tem/tem.py
f:\dev\tem\tem.py:5: RuntimeWarning: coroutine 'f' was never awaited
del f
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
>>> quit() Running in IDLE, I only see the first warning. (IDLE bug? python behavior difference? Don't know yet.) On 3.11, the remote process crashes and IDLE's Shell does an unrequested restart. |
On 3.11, both of the last two lines are required for the crash and restart. |
Thanks for testing it. Maybe it only crashes on Unix-like operating systems. I also try it on MacOS 11.6.1. with -i to ensure that python survives running the test code. On MacOS, it reports the following crashing information: ------------------- |
The crash in IDLE could be in tcl or any of the extra modules imported by IDLE, such as tkinter and socket. It should be retested on Windows once this appears fixed otherwise. |
I got a crash on Windows in Objects/genobject.c: void
_PyGen_Finalize(PyObject *self)
{
PyGenObject *gen = (PyGenObject *)self;
PyObject *res = NULL;
PyObject *error_type, *error_value, *error_traceback;
if (gen->gi_xframe == NULL || _PyFrameHasCompleted(gen->gi_xframe)) { <------- Crash is here
/* Generator isn't paused, so no need to close */
return;
}
... It looks like gen->gi_xframe is a junk-but-not-NULL pointer that is getting dereferenced by _PyFrameHasCompleted. Maybe related to bpo-44590. |
I think the import is irrelevant (luckily). This still crashes: async def f():
pass
frame = f().cr_frame
frame.clear() |
Even without garbage-collecting the coroutine, we get a failed assertion in debug mode (but no crash with the assertion removed): Python 3.11.0a2+ (heads/main:c8c21bdd19, Nov 21 2021, 13:58:01) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> async def f():
... pass
...
>>> coro = f()
>>> frame = coro.cr_frame
>>> frame.clear()
<stdin>:1: RuntimeWarning: coroutine 'f' was never awaited
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Assertion failed: f->f_frame->generator == NULL, file C:\Users\sween\Source\Repos\cpython2\cpython\Objects\frameobject.c, line 705 |
I'm seeing a similar failure on a debug build of 3.10 as well. ./python
Python 3.10.0+ (heads/3.10:9e7a2e4920, Nov 22 2021, 10:51:32) [GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> async def f():
... pass
...
>>> coro = f()
>>> frame = coro.cr_frame
>>> frame.clear()
<stdin>:1: RuntimeWarning: coroutine 'f' was never awaited
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
python: Objects/frameobject.c:695: frame_clear: Assertion `f->f_gen == NULL' failed.
Aborted (core dumped) I don't know why that assertion is there, it doesn't seem to be valid. |
I think the PR fixed one case, but the other case (when coro is kept around) still fails an assertion: Python 3.11.0a2+ (heads/main:734ed35383, Nov 29 2021, 19:29:25) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> async def f(): pass
...
>>> coro = f()
>>> frame = coro.cr_frame
>>> frame.clear()
<stdin>:1: RuntimeWarning: coroutine 'f' was never awaited
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Assertion failed: f->f_frame->generator == NULL, file C:\Users\sween\Source\Repos\cpython2\multiply\Objects\frameobject.c, line 689 Perhaps there should be some sort of backport as well? |
Pablo, I think #29990 should be merged as well before the issue closing. It covers another execution branch. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: