Skip to content

Commit bd5624b

Browse files
committed
Build/Test Tools: Avoid Node 24 hang on grunt exit
Grunt ends a successful run with `process.exit(0)`. Node's exit handler joins the V8 platform worker pool; if 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 printing "Done.". Node 24 enables both Maglev and concurrent Sparkplug, Node 22 enabled neither, which is why this only appears after the upgrade to Node 24. Disable both compilers from Gruntfile.js with v8.setFlagsFromString(). NODE_OPTIONS rejects V8 flags, so they cannot be set there, and setting them in the Gruntfile keeps every entry point plain `grunt`: nested grunt children, grunt-contrib-watch and tools/gutenberg/utils.js all load this same Gruntfile and inherit the change with no extra plumbing. The tradeoff is that 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, remains eligible for Maglev. Measured on Node 24.15 with `node --trace-opt node_modules/grunt/bin/grunt jshint`, counting "target MAGLEV" lines: 1443 unpatched, 88 with this change, 0 with the flags passed at process startup. The remaining 88 complete in microseconds, long before exit. See #66116, nodejs/node#64274.
1 parent 1612235 commit bd5624b

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎Gruntfile.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
/* jshint node:true */
22
/* globals Set */
3+
4+
/*
5+
* Disable V8's Maglev and concurrent Sparkplug compilers.
6+
*
7+
* Grunt ends a successful run with `process.exit(0)`. On Node 24, where both
8+
* compilers are enabled by default, Node's exit handler joins the V8 platform
9+
* worker pool while a background compile job may still be parked waiting for a
10+
* garbage collection the main thread will never run again, deadlocking the
11+
* build after it prints "Done.". See https://github.com/nodejs/node/issues/64274.
12+
*
13+
* Node refuses V8 flags in NODE_OPTIONS, so they are set here instead. This
14+
* only narrows the window: code compiled before this file is read is still
15+
* subject to the deadlock.
16+
*/
17+
require( 'v8' ).setFlagsFromString( '--no-maglev --no-concurrent-sparkplug' );
18+
319
var webpackConfig = require( './webpack.config' );
420
var installChanged = require( 'install-changed' );
521

0 commit comments

Comments
 (0)