diff --git a/test/fixtures/es-modules/tla/terminate-worker-tla.mjs b/test/fixtures/es-modules/tla/terminate-worker-tla.mjs new file mode 100644 index 00000000000..0a5e432fc91 --- /dev/null +++ b/test/fixtures/es-modules/tla/terminate-worker-tla.mjs @@ -0,0 +1 @@ +await 0; diff --git a/test/fixtures/es-modules/tla/terminate-worker.mjs b/test/fixtures/es-modules/tla/terminate-worker.mjs new file mode 100644 index 00000000000..183207f227a --- /dev/null +++ b/test/fixtures/es-modules/tla/terminate-worker.mjs @@ -0,0 +1,6 @@ +import { parentPort } from 'node:worker_threads'; +import './terminate-worker-tla.mjs'; + +parentPort.postMessage('running'); +const end = Date.now() + 5000; +while (Date.now() < end); diff --git a/test/parallel/test-worker-terminate-tla.mjs b/test/parallel/test-worker-terminate-tla.mjs new file mode 100644 index 00000000000..a676039b4c9 --- /dev/null +++ b/test/parallel/test-worker-terminate-tla.mjs @@ -0,0 +1,25 @@ +// Test: terminating a worker thread while it evaluates the parent module of a +// top-level-await module. +// +// worker.terminate() used to abort the whole process with a V8 CHECK failure +// (`Check failed: !is_null().`). See https://github.com/nodejs/node/issues/67550 +// and the V8 cherry-pick be84cdeee94e. + +import { mustCall } from '../common/index.mjs'; +import assert from 'node:assert'; +import { Worker } from 'node:worker_threads'; + +const worker = new Worker( + new URL('../fixtures/es-modules/tla/terminate-worker.mjs', import.meta.url), +); + +worker.on('error', (err) => assert.fail(err)); + +// The worker posts 'running' at the top of the parent module body and then +// busy-waits. Terminating at that point used to abort the entire process via a +// V8 CHECK failure in `AsyncModuleExecutionFulfilled`; after the fix it +// terminates cleanly with exit code 1. +worker.on('message', mustCall(async (message) => { + assert.strictEqual(message, 'running'); + assert.strictEqual(await worker.terminate(), 1); +}));