Skip to content

gh-158552: Wait for Windows threads to suspend before blocking sampling - #158802

Merged
pablogsal merged 2 commits into
python:mainfrom
pablogsal:codex/fix-158552-windows-suspension
Oct 5, 2026
Merged

pablogsal merged 2 commits into
python:mainfrom
pablogsal:codex/fix-158552-windows-suspension

Conversation

@pablogsal

Copy link
Copy Markdown
Member

Fixes #158552.

On Windows, NtSuspendProcess can return before the target's threads have actually stopped. The blocking sampler then reads memory while a thread is still updating it, so suspending the process does not reliably prevent inconsistent frame reads.

Wait for each target thread to stop with GetThreadContext before clearing the remote-memory cache and sampling. Enumerate threads with NtGetNextThread to avoid taking a system-wide thread snapshot on every sample, and resume the process if waiting for suspension fails.

@pablogsal
pablogsal merged commit 1643525 into python:main Oct 5, 2026
54 checks passed
@pablogsal
pablogsal deleted the codex/fix-158552-windows-suspension branch October 5, 2026 13:51
@pablogsal pablogsal added the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Oct 5, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Oct 5, 2026

Copy link
Copy Markdown

GH-158845 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Oct 5, 2026
pablogsal added a commit that referenced this pull request Oct 5, 2026
… sampling (GH-158802) (#158845)

gh-158552: Wait for Windows threads to suspend before blocking sampling (GH-158802)

* gh-158552: Wait for Windows threads to suspend before blocking sampling

* Use a named Windows thread enumeration status constant
(cherry picked from commit 1643525)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
pablogsal added a commit to pablogsal/cpython that referenced this pull request Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

profiling.sampling: --blocking sample-read error rate ~33% on AMD EPYC 9V45 (Windows), ~0.5% on other CPUs

1 participant