You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 frame->frame_obj != NULL when creating a generator, but there are bound other issues, as the generator and frame object are may not be an introspectable state.
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.
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.
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.
I'm concerned that this shows up from an interrupt. It shouldn't.
It was really hard to reproduce the error, my current theory is that if an interrupt happens while executing __del__ of an object and the interpreter creates a traceback to print, it can create a frame object for a generator and it causes a hard crash while the exception is propagated to the generator.
The problem isn't really the GC behavior* but that partially constructed frames are visible to Python and C extensions.
We fix this by not creating frame objects for partially constructed frames.
*The behavior of the GC and finalization is a problem, but not the problem here.
Activity
markshannon commentedon Jun 27, 2022
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
frame->frame_obj != NULLwhen creating a generator, but there are bound other issues, as the generator and frame object are may not be an introspectable state.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.
kumaraditya303 commentedon Jun 27, 2022
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
__del__of an object and the interpreter creates a traceback to print, it can create a frame object for a generator and it causes a hard crash while the exception is propagated to the generator.kumaraditya303 commentedon Jun 27, 2022
I was correct about my theory, the following code sample demonstrates how
KeyboardInterruptcan lead to crash:Crash:
markshannon commentedon Jun 27, 2022
Thanks @kumaraditya303 that's really helpful.
markshannon commentedon Jun 28, 2022
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.
We fix this by not creating frame objects for partially constructed frames.
*The behavior of the GC and finalization is a problem, but not the problem here.
GH-94262: Don't create frame objects for frames that aren't yet compl…
pythonGH-94262: Don't create frame objects for frames that aren't yet…
[3.11] GH-94262: Don't create frame objects for frames that aren't ye…
pablogsal commentedon Jul 4, 2022
Thanks, @markshannon and @kumaraditya303 for the work! 🎉