fix(register): do not inherit parent execArgv - #18131
Conversation
Per https://nodejs.org/api/worker_threads.html#launching-worker-threads-from-preload-scripts, new Worker threads will inherit command line flags, including `-e` and `-r`. When they are combined with the `--input-type`, Node.js somehow hangs and the worker does not start.
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/61899 |
|
commit: |
|
Is this a Node.js bug or intended behavior on their side? |
Error [ERR_INPUT_TYPE_NOT_ALLOWED]: --input-type can only be used with string input via --eval, --print, or STDIN
Amazing! Thanks to this, we can remove both |
|
@nicolo-ribaudo wrote
@liuxingbaoyu wrote
Yes, so what's happening here is that Node.js does not pass Here is a minimum reproduction case without babel-register: // server.js
import { parentPort, isMainThread, Worker } from "node:worker_threads";
if (isMainThread) {
const worker = new Worker(new URL(import.meta.url), { execArgv: process.execArgv });
const signal = new Int32Array(new SharedArrayBuffer(4), 0, 1);
worker.postMessage({ signal });
Atomics.wait(signal, 0, 0, 1000);
worker.unref();
} else {
parentPort.addListener("message", ({ signal }) => {
Atomics.store(signal, 0, 1);
Atomics.notify(signal, 0, 1);
});
}
Update: so any uncaught error thrown from the worker will emit the What we could do is to add a realistic timeout to the |
In this PR we avoid inheriting command line arguments for the babel-register worker, per the best practise mentioned in https://nodejs.org/api/worker_threads.html#launching-worker-threads-from-preload-scripts.
A new Worker threads will inherit command line flags, including
-r, but will discard the-eflag, when the--input-typeflag is passed down without-eflag, an error is thrown from the module loader, and the signal does not have a chance to change so theAtomics.waitwill block event loop indefinitely.We also add a new feature to the process fixture test: The test will now resolve the special
<rootDir>/<rootUrl>token into the root of the monorepo. With the new feature, we can properly test the behaviour of Node.js when@babel/registeris preloaded via--requireor--import.