mirror of
https://github.com/nodejs/node.git
synced 2025-04-29 14:25:18 +00:00

Do not emit `'exit'` events caused by recursively stopping all running Workers from inside the `process.exit()` call. PR-URL: https://github.com/nodejs/node/pull/32546 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
21 lines
790 B
JavaScript
21 lines
790 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { Worker, workerData } = require('worker_threads');
|
|
|
|
// Test that 'exit' events for nested Workers are not received when a Worker
|
|
// terminates itself through process.exit().
|
|
|
|
if (workerData === null) {
|
|
const nestedWorkerExitCounter = new Int32Array(new SharedArrayBuffer(4));
|
|
const w = new Worker(__filename, { workerData: nestedWorkerExitCounter });
|
|
w.on('exit', common.mustCall(() => {
|
|
assert.strictEqual(nestedWorkerExitCounter[0], 0);
|
|
}));
|
|
} else {
|
|
const nestedWorker = new Worker('setInterval(() => {}, 100)', { eval: true });
|
|
// The counter should never be increased here.
|
|
nestedWorker.on('exit', () => workerData[0]++);
|
|
nestedWorker.on('online', () => process.exit());
|
|
}
|