-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-125859: Fix crash when gc.get_objects
is called during GC
#125882
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
This fixes a crash when `gc.get_objects()` or `gc.get_referrers()` is called during a GC in the free threading build. Switch to `_PyObjectStack` to avoid corrupting the `struct worklist` linked list maintained by the GC. Also, don't return objects that are frozen (gc.freeze) or in the process of being collected to more closely match the behavior of the default build.
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.
LGTM
After the `_PyEval_StartTheWorld()` call, other threads may be running and mutating objects. Ensure that the objects are kept alive by incref'ing them when they're added to the `_PyObjectStack`.
@mpage - would you please re-review this? The previous version had a bug where the objects found during |
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.
LGTM
Thanks @colesbury for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13. |
…ythonGH-125882) This fixes a crash when `gc.get_objects()` or `gc.get_referrers()` is called during a GC in the free threading build. Switch to `_PyObjectStack` to avoid corrupting the `struct worklist` linked list maintained by the GC. Also, don't return objects that are frozen (`gc.freeze()`) or in the process of being collected to more closely match the behavior of the default build. (cherry picked from commit e545ead) Co-authored-by: Sam Gross <[email protected]>
GH-125921 is a backport of this pull request to the 3.13 branch. |
…GH-125882) (GH-125921) This fixes a crash when `gc.get_objects()` or `gc.get_referrers()` is called during a GC in the free threading build. Switch to `_PyObjectStack` to avoid corrupting the `struct worklist` linked list maintained by the GC. Also, don't return objects that are frozen (`gc.freeze()`) or in the process of being collected to more closely match the behavior of the default build. (cherry picked from commit e545ead) Co-authored-by: Sam Gross <[email protected]>
…ython#125882) This fixes a crash when `gc.get_objects()` or `gc.get_referrers()` is called during a GC in the free threading build. Switch to `_PyObjectStack` to avoid corrupting the `struct worklist` linked list maintained by the GC. Also, don't return objects that are frozen (`gc.freeze()`) or in the process of being collected to more closely match the behavior of the default build.
This fixes a crash when
gc.get_objects()
orgc.get_referrers()
is called during a GC in the free threading build.Switch to
_PyObjectStack
to avoid corrupting thestruct worklist
linked list maintained by the GC. Also, don't return objects that are frozen (gc.freeze()
) or in the process of being collected to more closely match the behavior of the default build.gc.get_objects
can corrupt in-progress GC in free threading build #125859