-
-
Notifications
You must be signed in to change notification settings - Fork 37.5k
Torn reads of GC statistics from external process via get_gc_stats #155811
Copy link
Copy link
Closed
Labels
3.15pre-release feature fixes, bugs and security fixespre-release feature fixes, bugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Activity
Metadata
Metadata
Assignees
Labels
3.15pre-release feature fixes, bugs and security fixespre-release feature fixes, bugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Bug report
Bug description:
If an external tool sampling GC statistics does not pause the target process (and we designed
get_gc_statsnot to pause), it can read torn data under certain circumstances.There are two distinct problems:
Weakly ordered platforms: The stores of
ts_startandts_stopmay be reordered by the CPU/optimizer. We need to add memory barriers to mitigate this.Large memcpy window: We are copying a sufficiently large memory region via
memcpy. If two or more GC cycles occur during this copy, we can end up with inconsistent data spanning multiple GC states.@maurycy has an idea to use a sequence counter for consistency checks — I think he should definitely give it a try.
cc @pablogsal
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
gc_statsto prevent torn reads #155828gc_statsto prevent torn reads (GH-155828) #158829