-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-111777: Fix assertion errors on incorrectly still-tracked GC object destruction #111778
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
Conversation
were not properly untracked before starting destruction, take care to untrack the object _before_ warning, to avoid triggering a GC run and causing the problem the code tries to warn about. Also make sure to save and restore any pending exceptions, which the warning would otherwise clobber or trigger an assertion error on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be great to have a test but I understand that's not easy to trigger so this is fine with me. (I am assuming you tested this locally @ Google)
Yeah, it's difficult to reproduce either real-world case. Deliberately setting an exception a custom tp_dealloc before calling PyObject_GC_Del is possible, but it's not really representative of the real case (the error would be set further up the call stack). The other case, with the warning triggering a GC run, I've completely failed to reproduce. It requires quite a complex interplay, apparently. I'm still debugging related issues, though, involving the untracking of GC objects, instances of heap types, subclassing in C, subclassing in Python, and custom tp_dealloc/tp_free, which has some subtle issues that elude me. I may be able to synthesise a good test in the end, but I think this fix is straight-forward enough to do without. And yes, this fix has solved crashes in two different extension modules with the same problem at Google (in Py_DEBUG mode), without us having to fix the warnings. (We'll still fix the warnings, but at least this unblocks further testing.) |
Thanks @Yhg1s for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12. |
… object destruction (pythonGH-111778) In PyObject_GC_Del, in Py_DEBUG mode, when warning about GC objects that were not properly untracked before starting destruction, take care to untrack the object _before_ warning, to avoid triggering a GC run and causing the problem the code tries to warn about. Also make sure to save and restore any pending exceptions, which the warning would otherwise clobber or trigger an assertion error on. (cherry picked from commit ce6a533) Co-authored-by: T. Wouters <[email protected]>
… object destruction (pythonGH-111778) In PyObject_GC_Del, in Py_DEBUG mode, when warning about GC objects that were not properly untracked before starting destruction, take care to untrack the object _before_ warning, to avoid triggering a GC run and causing the problem the code tries to warn about. Also make sure to save and restore any pending exceptions, which the warning would otherwise clobber or trigger an assertion error on. (cherry picked from commit ce6a533) Co-authored-by: T. Wouters <[email protected]>
GH-111989 is a backport of this pull request to the 3.12 branch. |
GH-111990 is a backport of this pull request to the 3.11 branch. |
…C object destruction (GH-111778) (#111989) gh-111777: Fix assertion errors on incorrectly still-tracked GC object destruction (GH-111778) In PyObject_GC_Del, in Py_DEBUG mode, when warning about GC objects that were not properly untracked before starting destruction, take care to untrack the object _before_ warning, to avoid triggering a GC run and causing the problem the code tries to warn about. Also make sure to save and restore any pending exceptions, which the warning would otherwise clobber or trigger an assertion error on. (cherry picked from commit ce6a533) Co-authored-by: T. Wouters <[email protected]>
…C object destruction (GH-111778) (GH-111990) In PyObject_GC_Del, in Py_DEBUG mode, when warning about GC objects that were not properly untracked before starting destruction, take care to untrack the object _before_ warning, to avoid triggering a GC run and causing the problem the code tries to warn about. Also make sure to save and restore any pending exceptions, which the warning would otherwise clobber or trigger an assertion error on. (cherry picked from commit ce6a533) Co-authored-by: T. Wouters <[email protected]>
… object destruction (python#111778) In PyObject_GC_Del, in Py_DEBUG mode, when warning about GC objects that were not properly untracked before starting destruction, take care to untrack the object _before_ warning, to avoid triggering a GC run and causing the problem the code tries to warn about. Also make sure to save and restore any pending exceptions, which the warning would otherwise clobber or trigger an assertion error on.
… object destruction (python#111778) In PyObject_GC_Del, in Py_DEBUG mode, when warning about GC objects that were not properly untracked before starting destruction, take care to untrack the object _before_ warning, to avoid triggering a GC run and causing the problem the code tries to warn about. Also make sure to save and restore any pending exceptions, which the warning would otherwise clobber or trigger an assertion error on.
In PyObject_GC_Del, in Py_DEBUG mode, when warning about GC objects that were not properly untracked before starting destruction, take care to untrack the object before warning, to avoid triggering a GC run and causing the problem the code tries to warn about. Also make sure to save and restore any pending exceptions, which the warning would otherwise clobber or trigger an assertion error on.