gh-151424: Fix impossible stack traces in RemoteUnwinder(..., cache_frames=True) by copying chunks on cache miss#151426
Merged
Merged
Conversation
RemoteUnwinder(..., cache_frames=True)RemoteUnwinder(..., cache_frames=True) by copying chunks on cache miss
pablogsal
approved these changes
Jun 13, 2026
pablogsal
left a comment
Member
There was a problem hiding this comment.
Thanks! This is a good catch! Notice in general this problem is the reason --blocking exists as its impossible to fix this properly unfortunately. But this is a good fix
|
Thanks @maurycy for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15. |
|
GH-151459 is a backport of this pull request to the 3.15 branch. |
pablogsal
pushed a commit
that referenced
this pull request
Jun 13, 2026
… cache_frames=True)` by copying chunks on cache miss (GH-151426) (#151459) gh-151424: Fix impossible stack traces in `RemoteUnwinder(..., cache_frames=True)` by copying chunks on cache miss (GH-151426) (cherry picked from commit 6ce088e) Co-authored-by: Maurycy Pawłowski-Wieroński <maurycy@maurycy.com>
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%.
_remote_debugging: Impossible stack traces (cross calls, orphans, wrong lines) withcache_frames=True#151424