Repository navigation
🐛 fix(ci): parallelize graalpy tests, recover crashed workers - #3240
Merged
Merged
Conversation
gaborbernat
enabled auto-merge (squash)
September 16, 2026 22:33
A pytest-timeout SIGALRM fired mid-traceback-formatting on graalpy under -n auto, corrupting xdist state into an unrecoverable INTERNALERROR. Switch its timeout method to thread, which hard-kills the worker instead and lets xdist's crash recovery take over. Also pass PYTHONFAULTHANDLER through tox so a future silent worker crash (as seen on 3.13t/Windows) gets a native stack trace instead of nothing; tox's pass_env allowlist was silently stripping it.
The Ubuntu leg of #3240's own validation run needed 11 reruns and still had 2 hard failures, all tests/unit/activation/test_fish.py cases on the same worker slot, timing out at the existing 120s limit. The rerun that did land under load ran in 44s standalone, so the tests aren't broken; GraalPy's JIT warmup across `-n auto` workers on a shared runner was starving them of CPU. Dropping to `-n 2` cuts that contention directly instead of just giving failing tests more rope. Bumped the per-test timeout to 300s for graalpy on top of that as a margin, since even under less contention subprocess-heavy shell-activation tests can run slower on GraalPy than the 120s default assumes.
-n 2 cut the timeout-driven reruns to zero and made the run faster, but a fully clean run (394 passed, 0 reruns) still crashed 26s after finishing: "IllegalStateException: The language did not complete all polyglot threads but should have: [Thread[...,Polyglot-python-1,...]]". execnet, pytest-xdist's transport, keeps a background reader thread alive on the controller for each worker gateway (see execnet#96). GraalVM's Context.close() apparently requires every Python-visible thread to have exited first, daemon or not, and won't wait past its own internal ~26-28s grace period. -n 2 lowered the odds of losing that race; it never removed the thread that could lose it. Dropping -n/--dist for graalpy removes execnet from the picture entirely, which removes the thread. Bumped its job/step timeouts to cover running the suite serially instead of on 2 workers.
Removing xdist (previous commit) didn't fix the interpreter-shutdown crash: a fully serial run with zero reruns still hit the identical "did not complete all polyglot threads" error, same thread number (#54), same ~26s gap after the suite finished. pytest-timeout's --timeout-method=thread, added earlier specifically to survive SIGALRM corrupting xdist workers, spawns a watcher thread per test. GraalVM's Context.close() won't tolerate any Python-visible thread still alive, daemon or not, regardless of what created it. Now that xdist is gone, the reason for the thread method is gone too: plain pytest-timeout defaults to signal-based (SIGALRM) enforcement, which needs no thread at all, and GraalPy isn't run on Windows so the Unix-only signal method is safe. This matches the graalpy env's config from before any of today's changes, which never hit this.
Two prior commits removed xdist and its thread-based timeout method from the graalpy env, each time expecting to eliminate the extra thread they believed GraalVM's Context.close() was choking on. Both were wrong: a run with the graalpy env restored to its exact pre-#3240 config (no xdist, no --timeout-method override, the same config that has run clean on other PRs) crashed with the identical "did not complete all polyglot threads" error, same thread number, same ~26s shutdown delay. That rules out anything in our control as the trigger. This is a nondeterministic crash in GraalVM's own interpreter teardown that predates all of today's changes, not something caused or fixable by tuning xdist workers or pytest-timeout's method. tasks/run_graalpy_tests.py wraps the pytest invocation: if it exits non-zero but the JUnit report it just wrote shows zero failed or errored tests, the wrapper treats the run as a pass instead of failing the build. Any real test failure still fails normally, since the JUnit report would show it.
gaborbernat
disabled auto-merge
September 17, 2026 03:52
This was referenced Sep 17, 2026
gaborbernat
added a commit
to gaborbernat/virtualenv
that referenced
this pull request
Sep 27, 2026
GraalPy cannot use pytest-xdist because its worker threads trip GraalVM's Context.close() check (pypa#3240). The suite ran in one process and hit the 65 minute step timeout on ubuntu-24.04. The runner now starts one serial pytest process per CPU. A --shard=K/N option in the test conftest gives each process every Nth test ID in sorted order, so the slices agree even though pytest-randomly shuffles each process in its own order. Each shard keeps the polyglot shutdown tolerance, and the run fails if any shard fails or no test ran. The graalpy env also stops tracing coverage: no step combines or reports it, and tracing every GraalPy process cost about five times the CPU time.
gaborbernat
added a commit
to gaborbernat/virtualenv
that referenced
this pull request
Sep 27, 2026
GraalPy cannot use pytest-xdist because its worker threads trip GraalVM's Context.close() check (pypa#3240). The suite ran in one process and hit the 65 minute step timeout on ubuntu-24.04. The runner now starts one serial pytest process per CPU. A --shard=K/N option in the test conftest gives each process every Nth test ID in sorted order, so the slices agree even though pytest-randomly shuffles each process in its own order. Each shard keeps the polyglot shutdown tolerance, and the run fails if any shard fails or no test ran.
gaborbernat
added a commit
to gaborbernat/virtualenv
that referenced
this pull request
Sep 27, 2026
GraalPy cannot use pytest-xdist because its worker threads trip GraalVM's Context.close() check (pypa#3240). The suite ran in one process and hit the 65 minute step timeout on ubuntu-24.04. The runner now starts one serial pytest process per CPU. A --shard=K/N option in the test conftest gives each process every Nth test ID in sorted order, so the slices agree even though pytest-randomly shuffles each process in its own order. Each shard keeps the polyglot shutdown tolerance, and the run fails if any shard fails or no test ran.
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.
Two jobs on #3238 failed for reasons unrelated to that PR's diff, which only touched a workflow file and a README badge.
graalpy-24.1 - ubuntu-24.04hit the hard 30-minute step timeout, and3.13t - windows-2025-vs2026failed withworker 'gw0' crashed while running 'tests/unit/create/test_creator.py::test_get_site_packages'. Neither is a test regression, so re-running the job would have hidden both without fixing anything.[env.graalpy]intox.tomloverridescommandsand, unlike every other environment inherited from[env_run_base], drops the-n auto --dist loadfilexdist flags, so it was the only environment in the matrix running the suite one test at a time;tox config -e graalpyconfirmed the resolved command had no-nflag before this change. The Windows failure is a realpytest-xdistworker crash:test_get_site_packagesbuilds a virtualenv, then spawns a subprocess of its free-threaded interpreter from inside an xdist worker, andpytest-xdistmarks a test failed when its worker dies mid-run instead of retrying it.pytest-rerunfailures's own README documents that it can recover a hard worker crash when paired with-n, soPYTEST_ADDOPTSnow carries--reruns 2 --reruns-delay 2for CI 🔁, leaving localtox runfailing on the first try as before.pytest-rerunfailuresis incompatible with theflakyplugin.flakywas a dependency with zero@flakyusage anywhere in the codebase, so it and its now-meaningless--no-success-flaky-reportaddopt go, rather than risk a plugin conflict. Thegraalpy-24.1job gets more headroom too (50/40 minutes vs 40/30). Its per-process startup runs slower 🐢 than CPython's.