Skip to content

gh-151613: Fix remote debugging frame cache ABA#151614

Open
pablogsal wants to merge 1 commit into
python:mainfrom
pablogsal:gh-151613-remote-debugging-frame-cache-aba
Open

gh-151613: Fix remote debugging frame cache ABA#151614
pablogsal wants to merge 1 commit into
python:mainfrom
pablogsal:gh-151613-remote-debugging-frame-cache-aba

Conversation

@pablogsal

@pablogsal pablogsal commented Jun 17, 2026

Copy link
Copy Markdown
Member

Fixes #151613.

The remote debugging frame cache previously used only the last_profiled_frame address as its cache anchor. If a frame returned and a later frame reused the same _PyInterpreterFrame address, the profiler could accept a stale cache entry and splice parent frames from a different call chain into the current stack.

This adds a last_profiled_frame_seq counter next to last_profiled_frame, increments it when the anchor advances, stores it in frame cache entries, and validates cache hits against both the frame address and the sequence. Cache miss walks now copy stack chunks before storing new cache entries so stored continuations come from a stable snapshot. The new regression test exercises alternating call chains and checks that cached stacks never contain frames from both branches.

@pablogsal pablogsal force-pushed the gh-151613-remote-debugging-frame-cache-aba branch from 000eedb to 9f447d8 Compare June 17, 2026 21:25
@pablogsal pablogsal marked this pull request as ready for review June 17, 2026 21:31
@pablogsal pablogsal force-pushed the gh-151613-remote-debugging-frame-cache-aba branch 2 times, most recently from 418a947 to a548b24 Compare June 17, 2026 21:46
Fixes python#151613.

The remote debugging frame cache previously used only the last_profiled_frame address as its cache anchor. If a frame returned and a later frame reused the same _PyInterpreterFrame address, the profiler could accept a stale cache entry and splice parent frames from a different call chain into the current stack.

This adds a last_profiled_frame_seq counter next to last_profiled_frame, increments it when the anchor advances, stores it in frame cache entries, and validates cache hits against both the frame address and the sequence. Cache miss walks now copy stack chunks before storing new cache entries so stored continuations come from a stable snapshot. The new regression test exercises alternating call chains and checks that cached stacks never contain frames from both branches.
@pablogsal pablogsal force-pushed the gh-151613-remote-debugging-frame-cache-aba branch from a548b24 to fc9fafd Compare June 17, 2026 22:06
@pablogsal pablogsal requested a review from AA-Turner as a code owner June 17, 2026 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_remote_debugging frame cache can reuse stale frame anchors

1 participant