Skip to content

test: dump child tracebacks on GIL test deadlock, widen slow-exit budget - #6293

Merged
rwgk merged 2 commits into
pybind:masterfrom
henryiii:test/gil-scoped-harness
Nov 22, 2026
Merged

rwgk merged 2 commits into
pybind:masterfrom
henryiii:test/gil-scoped-harness

Conversation

@henryiii

@henryiii henryiii commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

🤖 AI text below 🤖

Description

Two changes to the test_gil_scoped.py subprocess harness:

  • The child process runs faulthandler.dump_traceback_later(repeat=True) into a temporary file. On a DEADLOCK, the parent adds the last dump to the error message. This is for rare hangs such as test_run_in_process_multiple_threads_sequential[first_use_gil_acquired] on Windows 3.14t, where CI gave no stack.
  • test_run_in_process_slow_start_or_exit[shutdown] gave the callback 0.1 s, which failed on GraalPy macOS. It now uses 0.5 s, with a delay of twice the timeout, so a harness that counts the delay still fails.

I checked locally that an intentional deadlock now shows the child's Python stack in the error.

The subprocess harness now records faulthandler dumps in the child and
adds the last one to the DEADLOCK error, so rare CI hangs show where
each thread stopped.

test_run_in_process_slow_start_or_exit gave the callback only 0.1 s,
which is too short for GraalPy. Use 0.5 s and a delay of twice that.

Assisted-by: ClaudeCode:claude-opus-5-5
@henryiii

Copy link
Copy Markdown
Collaborator Author

🤖 AI text below 🤖

I checked every failed job attempt in CI since Nov 1 for test_gil_scoped failures. This includes first attempts that passed when they were run again.

Run Date Branch Job Test Error
41713185563 (attempt 1) Nov 3 stable-abi macOS graalpy-25.0 slow_start_or_exit[startup] Subprocess did not start within 10 seconds
42351173606 (attempt 1) Nov 7 stable-abi macOS graalpy-25.0 slow_start_or_exit[startup] Subprocess did not start within 10 seconds
44935462102 Nov 21 fix/eigen-nondivisible-stride macOS graalpy-25.3 slow_start_or_exit[shutdown] DEADLOCK
44986011868 Nov 22 fix/keep-subcasters-alive Windows 3.14t C++23 multiple_threads_sequential[first_use_gil_acquired] DEADLOCK
  • The Windows 3.14t DEADLOCK occurred one time. The faulthandler dump in this PR is for the next time it occurs.
  • The [shutdown] failure is what the larger budget in this PR fixes.
  • The two [startup] failures are a different problem: the GraalPy child took more than 10 s to spawn and import. This PR does not fix them, and the larger 1 s delay makes them a little more likely. The other test_run_in_process_* tests already skip GraalPy, so skipping this harness self-test on GraalPy too does not remove pybind11 coverage.

@rwgk

rwgk commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

Sharing the initial codex review below. I'll add a commit in a few minutes.

codex GPT-6.2-Sol ultra:

I’d approve #6293 after one small fix. Cancel the traceback watchdog in a finally block while its file is still open. If the child target raises, the current code closes the file with the repeating watchdog still armed. I reproduced the watchdog writing a traceback into a different file that reused the descriptor. I’d also arm the watchdog before sending started and send finished as soon as the target returns. That keeps watchdog setup and cleanup outside the callback’s execution budget. PR code · Python descriptor rules

  • Why increase the timeout? The linked Windows 3.14t hang motivated the traceback dump. That test still gets 10 seconds. The increase from 0.1 to 0.5 seconds applies to a separate harness self-test that failed on macOS GraalPy. In that run, the child sent started but missed the 100 ms window to send finished. The deliberate startup or shutdown delay grows to 1 second so the self-test still catches a harness that counts either delay against the callback budget. Windows failure · GraalPy failure
  • Should the two 0.9s share a name? I’d name the new calculation traceback_interval and leave the existing assertion alone. The new factor gives the watchdog a head start before the parent times out. The old factor is a sanity check on total elapsed time, including startup. Those choices can vary independently. I’d also soften “always” in the comment, since scheduling can eat the lead time. Watchdog · Elapsed-time check

On Linux CPython 3.15.2, test_gil_scoped.py had 35 passes with the GIL and 31 passes with four expected skips on the free-threaded build. A separate forced hang produced the child stack on the PR head. The base reported only DEADLOCK.

Keep watchdog setup and teardown outside the callback budget. Cancel the timer even when the child target raises, while the traceback file descriptor is still valid.

@rwgk rwgk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@henryiii I added commit 95d2164

LGTM, but leaving merging to you, so you can review the new commit from your end.

@rwgk
rwgk merged commit b66ca61 into pybind:master Nov 22, 2026
94 checks passed
@rwgk
rwgk deleted the test/gil-scoped-harness branch November 22, 2026 19:30
@github-actions github-actions Bot added the needs changelog Possibly needs a changelog entry label Nov 22, 2026
@rwgk

rwgk commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

@henryiii In the meantime I changed my mind: I just merged this PR after seeing that the CI is green, so that we get the benefit of seeing the tracebacks while we work through the rest of the open PRs. If you discover issues with my added commit, we can handle them in a follow-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs changelog Possibly needs a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants