Repository navigation
Probable fix to tracing regions - #113
Open
TobiasWrigstad wants to merge 1 commit into
Open
TobiasWrigstad wants to merge 1 commit into
TobiasWrigstad wants to merge 1 commit into
Conversation
The close only checked that the LRC summed over all traced objects was zero. An object counted through more internal references than its recorded RC has a negative balance, which can cancel references from outside on other objects. A thread holding `a` and `b` in a region can move items from `a` to `b` between the two traversals without any refcount operation (e.g. a pop followed by a stealing store): each item is counted twice (-1), cancelling the +1 of each held list, and the region closes while the thread still holds both. Neither the trace flag nor the RC re-read sees this, since no refcount changes. With no object allowed below zero, a zero total means every object balances. The error is raised after the restart check, since code run by freezing during a trace may move references that a fresh trace counts correctly. Adds a debug-only trace hook, called after each traversed object, and _testinternalcapi.region_set_trace_move() to reproduce the move. The test fails without the check on both GIL and free-threaded builds.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reject closes that count an object more often than its RC allows
The close only checked that the LRC summed over all traced objects was
zero. An object counted through more internal references than its
recorded RC has a negative balance, which can cancel references from
outside on other objects. A thread holding
aandbin a region canmove items from
atobbetween the two traversals without anyrefcount operation (e.g. a pop followed by a stealing store): each item
is counted twice (-1), cancelling the +1 of each held list, and the
region closes while the thread still holds both. Neither the trace flag
nor the RC re-read sees this, since no refcount changes.
With no object allowed below zero, a zero total means every object
balances. The error is raised after the restart check, since code run
by freezing during a trace may move references that a fresh trace
counts correctly.
Adds a debug-only trace hook, called after each traversed object, and
_testinternalcapi.region_set_trace_move() to reproduce the move. The
test fails without the check on both GIL and free-threaded builds.
📚 Documentation preview 📚: https://cpython-previews--113.org.readthedocs.build/