-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gc.get_objects
can corrupt in-progress GC in free threading build
#125859
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
Hi @colesbury, if there is no objection, I would like to take over this task. I will submit a PR in the next few days. I will take plan |
@rruuaanng - thank you for the offer, but I've already started working on this |
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()` 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.
…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-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.
Uh oh!
There was an error while loading. Please reload this page.
Bug report
Background
The free threading GC uses two queue-like data structures to keep track of objects:
struct worklist
, which is a singly linked list that repurposesob_tid
for the linked list pointer_PyObjectStack
, which is effectively a dynamically sized array ofPyObject*
. (Implemented using a linked list of fixed size array buffers).The
struct worklist
data structure is convenient because enqueueing objects doesn't require a memory allocation and so can't fail. However, an object can only be part of one "worklist" at a time, because each object has only oneob_tid
field.Bug
Other threads can run while the GC is finalizing cyclic garbage and while it's calling
tp_clear()
and other clean-up.During that time, some thread may call
gc.get_objects()
, which can return otherwise "unreachable" objects. The implementation of_PyGC_GetObjects
temporarily pushes objects to astruct worklist
, including objects that might already be part of some other worklist, overwriting the linked list pointer. This essentially corrupts the state of the in-progress GC and causes assertion failures.Proposed fix
_PyGC_BITS_UNREACHABLE
) from being returned bygc.get_objects()
struct worklist
to the actual GC and use_PyObjectStack
(or some other data structure) in_PyGC_GetObjects()
. This reduces the risk of bugs causing an object to be added to more than one worklist.Linked PRs
gc.get_objects
is called during GC #125882gc.get_objects
is called during GC (GH-125882) #125921The text was updated successfully, but these errors were encountered: