gh-151424: Fix impossible stack traces in RemoteUnwinder(..., cache_frames=True) by copying chunks on cache miss#151426
Open
maurycy wants to merge 3 commits into
Open
gh-151424: Fix impossible stack traces in RemoteUnwinder(..., cache_frames=True) by copying chunks on cache miss#151426maurycy wants to merge 3 commits into
RemoteUnwinder(..., cache_frames=True) by copying chunks on cache miss#151426maurycy wants to merge 3 commits into
Conversation
RemoteUnwinder(..., cache_frames=True)RemoteUnwinder(..., cache_frames=True) by copying chunks on cache miss
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.
The issue is caused by memory walks with
cache_frames=Truewhen there's a cache miss.If I understand the whole machniery correctly.
Basically, we don't copy chunks in cache mode:
cpython/Modules/_remote_debugging/threads.c
Lines 506 to 512 in f4f1020
So there are never any chunks in the cache mode, not a problem with full cache hits:
cpython/Modules/_remote_debugging/frames.c
Lines 328 to 351 in f4f1020
But when there's no cache hit:
cpython/Modules/_remote_debugging/frames.c
Lines 578 to 585 in f4f1020
it falls back to many memory reads:
cpython/Modules/_remote_debugging/frames.c
Line 315 in f4f1020
cpython/Modules/_remote_debugging/frames.c
Lines 236 to 242 in f4f1020
which isn't very atomic... the target mutates between reads and we're lost.
That's definitely the cause. Is there a cleaner fix ?
One side-note - let's not tighten the validation yet?
Generally, it's a statistical profiler so we should have some statistical tests for correctness, too.
Proof
Reusing
from #151424 we get
The impossible rate went to just 0,20%.