-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
Crash when inspecting frame of generator #94262
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
Comments
This is tricky. The fundamental problem, IMO, is that almost any memory allocation can run arbitrary code. This makes it really difficult to reason about the state of the VM. In the short term, we should handle the case where In the longer term, I'd like to only run the GC, and/or finalizers, when the VM is a known state; as we do with interrupts. I'm concerned that this shows up from an interrupt. It shouldn't. |
I agree, not only the state of VM but also any other object state can be mutated which in some can lead to memory leak or worse crash.
It was really hard to reproduce the error, my current theory is that if an interrupt happens while executing |
I was correct about my theory, the following code sample demonstrates how import gc
gc.set_threshold(1, 0, 0)
class Sneaky:
def __del__(self):
raise KeyboardInterrupt
def gen():
yield 1
sneaky = Sneaky()
sneaky._s = Sneaky()
sneaky._s._s = sneaky
del sneaky
g = gen() Crash: Exception ignored in: <function Sneaky.__del__ at 0x7fbfa49220a0>
Traceback (most recent call last):
File "/workspaces/cpython/main.py", line 6, in __del__
raise KeyboardInterrupt
^^^^^^^^^^^^^^^^^^^^^^^
KeyboardInterrupt:
Exception ignored in: <function Sneaky.__del__ at 0x7fbfa49220a0>
Traceback (most recent call last):
File "/workspaces/cpython/main.py", line 6, in __del__
raise KeyboardInterrupt
^^^^^^^^^^^^^^^^^^^^^^^
KeyboardInterrupt:
python: Python/ceval.c:5477: _PyEval_EvalFrameDefault: Assertion `frame->frame_obj == NULL' failed. |
Thanks @kumaraditya303 that's really helpful. |
Turns out that the fix isn't that hard. The problem isn't really the GC behavior* but that partially constructed frames are visible to Python and C extensions. *The behavior of the GC and finalization is a problem, but not the problem here. |
… complete. (pythonGH-94371) (cherry picked from commit 544531d) Co-authored-by: Mark Shannon <[email protected]>
…t complete. (GH-94371) (#94482) Co-authored-by: Mark Shannon <[email protected]>
Thanks, @markshannon and @kumaraditya303 for the work! 🎉 |
Crash report
This was discovered in an
asyncio
program when interrupted with CTRL - C.Minimal Reproducer:
Error messages
Your environment
cc @markshannon @pablogsal
The text was updated successfully, but these errors were encountered: