Skip to content

[3.14] gh-151518: Avoid STW starvation of attaching threads (GH-152826) - #158187

Open
tpn wants to merge 1 commit into
python:3.14from
tpn:codex/gh-151518-backport-314
Open

tpn wants to merge 1 commit into
python:3.14from
tpn:codex/gh-151518-backport-314

Conversation

@tpn

@tpn tpn commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Backport of gh-152826, merged as f156510, for gh-151518.

A tight loop of stop-the-world pauses can repeatedly suspend a thread trying to reattach after sleeping, preventing it from returning and stopping the loop. This was found during intentional numba-cuda GC stress on many-core machines. The fix preserves active attach waiters across successive pauses so they have a chance to run.

This branch predates gh-157839, so the waiter-aware resume operation is a private helper in pystate.c. The attachment changes, regression test, and guard that avoids blocking waits on WASI are carried over from the merged fix.

Validation:

  • Free-threaded debug and TSan: all 31 focused threading, GC, and asyncio tests passed.
  • With only the test changes, the unfixed branch hits the 30-second watchdog with 4 and 64 CPUs. The backport passes three runs each with 1, 4, and 64 CPUs.
  • Internal C API helper tests, including test_stop_the_world: all 16 passed in the ordinary GIL build and all 13 available tests passed on WASI, using this branch's SDK 24 and Wasmtime 38.0.3 toolchain.

CI note: the macOS free-threaded rerun passed after an IDLE SIGINT interruption on the first run. Both Windows ARM64 jobs fail before compilation because the runner lacks the requested Visual Studio v143 toolset. The unmodified 3.14 parent has the same failures on the same runner image.

Preserve active attach waiters across successive stop-the-world pauses.
Adapt the resume transition to the 3.14 stop-the-world implementation
and include the regression test and free-threaded test helper.

(cherry picked from commit f156510)
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.

1 participant