Repository navigation
Conversation
…dates On CPython < 3.12 the cyclic GC can run inside ContextVar.set()/reset(). A garbage object with a trampolined __del__ then touches the half-updated ContextVar, which corrupts it and segfaults stats collection (boxed#596). Track a per-thread "busy" flag around set()/reset(). While it is set, get() reports no caller and set()/reset() do nothing, so such a finalizer is simply not tracked. No process-wide GC state is touched.
…thread errors with the test
Independent review asked for the CPython root cause to be worded as believed, not established, and for the reset() re-entrancy branch to be covered by a test.
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.
Summary
MutmutCallStackaccess on Python < 3.12 when a finalizer interrupts aContextVar.set()orreset().__del__, a finalizer that calls another tracked function, and a multithreaded non-regression case.Fixes #596.
Verification
-11on the unmodified base and passes with this patch.pre-commit run --all-files --show-diff-on-failurepassed, including Ruff and mypy.test_setproctitle_crashes_after_fork_with_corefoundation_loaded, which also fails on the current unmodified upstream head on this Mac.The precise CPython failure mechanism and the 3.12 version boundary are inferred from the reproduction and linked CPython reports, rather than independently proven here. The interrupted finalizer's caller edge is intentionally omitted.
AI tooling assisted the investigation, patch preparation, and validation. I will own follow-up and review on this PR.