#66116 closed defect (bug) (fixed)
PHPUnit workflow jobs hang after grunt completes on Node.js 24
| Reported by: | johnbillion | Owned by: | lancewillett |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.2 |
| Component: | Build/Test Tools | Version: | trunk |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: |
Description
Since the Node.js 24 upgrade in [63539], jobs in the PHPUnit Tests workflow intermittently stall in the "Build WordPress" step until the 30 minute timeout-minutes cancels them.
Example: https://github.com/WordPress/wordpress-develop/actions/runs/35084237102/job/104755596536 (3 jobs cancelled).
Also seen on a trunk push: https://github.com/WordPress/wordpress-develop/actions/runs/34872993852
npm run build:dev completes every task and grunt logs Done after about 30 seconds. The node process then never exits.
Change History (17)
This ticket was mentioned in PR #13564 on WordPress/wordpress-develop by @johnbillion.
2 months ago
#1
- Keywords has-patch added
@johnbillion commented on PR #13564:
2 months ago
#3
#4
@
2 months ago
CC @manzoorwanijk @desrosj @ciampo
In r63643 the build step has been given its own 3 minute timeout so the stall doesn't cause the run to hang for the full 20/30 minutes.
@desrosj commented on PR #13564:
2 months ago
#6
Just noting that I've bumped this to 5 instead of 3 in r63647 because it was not quite long enough for some older branches to run reliably.
#7
@
2 months ago
I couldn’t reproduce this locally with repeated builds on Node 24.18.1 or Node 22.22.0, so I couldn't identify a specific Grunt task responsible.
A strong lead is a Node/V8 shutdown deadlock. Grunt explicitly calls process.exit(0) after printing Done., so the stall could happen during Node’s shutdown.
This upstream report describes a similar failure on Node 24.18.1 and Ubuntu: the main thread waits for background compiler threads to finish, while those threads wait for the main thread to perform garbage collection.
That looks relevant, but remains unconfirmed for this ticket. We would need matching thread stacks from a failing WordPress build before attributing it to the same cause.
#8
@
2 months ago
Confirming the lead in 7. I reproduced the stall locally and captured the matching thread stacks.
Grunt calls process.exit(0) after printing Done. (grunt/lib/grunt.js:163). Node's exit handler then joins the V8 platform worker threads, which are parked waiting for a garbage collection the main thread can no longer run:
main thread node::Environment::Exit -> DisposePlatform -> NodePlatform::Shutdown
-> WorkerThreadsTaskRunner::Shutdown -> uv_thread_join [blocked]
V8Worker x2 MaglevConcurrentDispatcher::JobTask::Run -> MaglevCompiler::Compile
-> HeapAllocator::AllocateRawWithRetryOrFailSlowPath
-> CollectionBarrier::AwaitCollectionBackground [blocked]
The event loop is already stopped, so no timer fires and nothing is left running, which fits the runner reporting only npm, sh and grunt as orphans.
Repro on macOS arm64 with Node 24.21.0: 3 stalls in 60 npm run build:dev runs. I watched for the process still being alive a few seconds after Done., then ran sample(1) on it. All three stacks were identical.
I also saw 0 stalls in 20 runs under node --no-maglev and 0 in 20 on Node 22.20.0, but at a 5% base rate those samples are too small to call either a fix. Maglev being on by default from Node 24 and off in 22 does fit the r63539 timing.
Upstream: nodejs/node#64274, still open.
Worth noting that Maglev is not the only candidate. --concurrent-sparkplug and --concurrent-recompilation are also on by default and allocate on the same worker pool, and the stack in the upstream report is a Sparkplug job rather than a Maglev one. So --no-maglev narrows the window without closing it, and any mitigation along those lines should be treated as a stopgap.
This ticket was mentioned in PR #13608 on WordPress/wordpress-develop by @manzoorwani.jk.
2 months ago
#9
Runs Grunt with V8's concurrent Maglev and Sparkplug compilers disabled, so builds stop hanging after Done..
Grunt ends a successful run with process.exit(0) (grunt.js:163). Node's exit handler joins the V8 platform worker pool, and when a background compile job is parked in CollectionBarrier::AwaitCollectionBackground waiting for a garbage collection the main thread can no longer run, the two deadlock:
main thread node::Environment::Exit -> DisposePlatform -> NodePlatform::Shutdown
-> WorkerThreadsTaskRunner::Shutdown -> uv_thread_join [blocked]
V8Worker x2 MaglevConcurrentDispatcher::JobTask::Run -> MaglevCompiler::Compile
-> HeapAllocator::AllocateRawWithRetryOrFailSlowPath
-> CollectionBarrier::AwaitCollectionBackground [blocked]
Node 24 turns on both --maglev and --concurrent-sparkplug, where Node 22 had neither, which is why this started with r63539. --concurrent-recompilation was already on under Node 22 and costs 2.2x build time to disable, so it is left alone. Upstream: nodejs/node#64274.
NODE_OPTIONS rejects V8 options, so [tools/grunt.js tools/grunt.js] carries them instead and every Grunt entry point routes through it. That includes the grunt script CI calls and the nested child in [tools/gutenberg/utils.js#L234 utils.js:234].
Previous attempts to contain this by timeout: #13564, r63643, r63647.
Testing instructions
- Run
npm run build:devand confirm the process exits rather than stalling afterDone.. - Run
npm run grunt jshintand confirm the exit code still propagates.
On macOS arm64 with Node 24.21.0 the stall appeared in 3 of 60 unpatched runs, always with the stack above, caught by running sample(1) on a process still alive after Done..
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code, Codex
Model(s): Claude Opus 5, GPT-5.3 Codex
Used for: Diagnosis, the native stacks, and drafting and reviewing the launcher. I verified the stacks, measurements and final change myself.
🤖 Generated with Claude Code
This ticket was mentioned in PR #13627 on WordPress/wordpress-develop by @lucatume.
8 weeks ago
#10
Exploration of an alternative to #13608, opened for comparison, not to replace it. Same diagnosis, same two V8 flags, different delivery: no launcher file, every entry point stays plain grunt.
Grunt ends a successful run with process.exit(0). Node's exit handler joins the V8 platform worker pool, and when a background compile job is parked in CollectionBarrier::AwaitCollectionBackground waiting for a garbage collection the main thread can no longer run, the two deadlock and the build hangs after Done.. Node 24 turns on both --maglev and --concurrent-sparkplug, where Node 22 had neither, which is why this started with r63539. Upstream: nodejs/node#64274.
NODE_OPTIONS rejects V8 options, and so does node-options in .npmrc. This sets the flags at runtime from Gruntfile.js instead:
require( 'v8' ).setFlagsFromString( '--no-maglev --no-concurrent-sparkplug' );
One file, no changes to package.json. Nested Grunt children, grunt-contrib-watch and [tools/gutenberg/utils.js#L234 utils.js:234] all load this same Gruntfile, so they inherit the flip with no extra plumbing.
Tradeoff
This narrows the window rather than closing it. Code compiled before Gruntfile.js is read, that is grunt-cli and Grunt's own module loading, is still eligible for Maglev. #13608 passes the flags at process startup and covers that too.
Measured on macOS arm64 with Node 24.15.0, counting target MAGLEV lines:
node --trace-opt node_modules/grunt/bin/grunt jshint 2>&1 | grep -c "target MAGLEV"
| Configuration | Maglev compilations |
|---|---|
| Unpatched | 1443 |
| This change | 88 |
| Flags at process startup (#13608) | 0 |
The residual 88 come from grunt-cli and Grunt's module loading and complete in microseconds, long before exit, so they are unlikely to be the job still parked when process.exit(0) runs. Unlikely is not never; whether that is an acceptable trade for dropping the launcher file is the question this PR is asking.
Testing instructions
- Run
npm run build:devand confirm the process exits rather than stalling afterDone.. - Run
npx grunt jshintand confirm the exit code still propagates. - Run the
--trace-optcommand above with and without the change and compare the counts.
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5
Used for: Drafting the change and running the measurements. I verified the measurements and the final change myself.
@manzoorwani.jk commented on PR #13608:
8 weeks ago
#11
After working on the upstream fix in Node - https://github.com/nodejs/node/pull/66171, I realized we can simplify the fix Claude Code helped me create for this.
@manzoorwani.jk commented on PR #13608:
8 weeks ago
#12
The change from
grunttonode ./tools/grunt.jsadds a bit of chore in the files and thetools/grunt.jsis a whole new wrapper file replicating some of Grunt's internals. Running scripts locally will now require usingnpm run gruntover justgrunt. The solution is not incorrect, but I tried to explore a lower impact solution in #13627 that has some caveats, see the PR, but might get the job done with less impact.
See https://github.com/WordPress/wordpress-develop/pull/13608#issuecomment-5759063994
@lucatume commented on PR #13608:
8 weeks ago
#13
I see little risk in the fix proposed in #13627, but get it that it's a question of what can be traded for what.
For the sake of the developers that will run this manually, can we document somewhere (not sure where) that the command to run is npm run grunt and not just grunt if we go with this fix?
@lancewillett commented on PR #13627:
8 weeks ago
#14
Going with #13608.
Since this PR was opened, #13608 dropped the launcher file in d4f125f. It's now +9/-9 across package.json and tools/gutenberg/utils.js, against +16 here, so lower impact no longer separates the two.
The deciding factor is the residual window documented above: 88 Maglev compilations versus 0 when the flags are set at process startup.
Nested Grunt children are covered either way. grunt.util.spawn( { grunt: true } ) builds its argv as process.execArgv.concat( process.argv[1], opts.args ) in grunt-legacy-util, and V8 flags passed on the command line do land in process.execArgv (verified on Node 24.16), so the nested build:gutenberg spawn in Gruntfile.js inherits them under #13608.
What #13608 gives up is bare grunt / npx grunt. No docs instruct that, and every CI call site uses npm run grunt.
---
<sub>Adversarial review · <code>claude-opus-5</code></sub>
Add a short timeout limit to the "Build WordPress" step so a stalled build doesn't need to wait for the full 30 minute timeout at the workflow level.
The build usually takes around 30 seconds so there's plenty of headroom.
See #66116, #65845