0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-worker-unref-from-message-during-exit.js
Anna Henningsen 48b159562d
worker: fix crash when .unref() is called during exit
To be more precise, fix a crash when `worker.unref()` is called
from a message on the Worker that is not emitted before the Worker
thread has stopped.

PR-URL: https://github.com/nodejs/node/pull/33394
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-05-16 11:13:30 +02:00

17 lines
492 B
JavaScript

'use strict';
const common = require('../common');
const { Worker } = require('worker_threads');
// This used to crash because the `.unref()` was unexpected while the Worker
// was exiting.
const w = new Worker(`
require('worker_threads').parentPort.postMessage({});
`, { eval: true });
w.on('message', common.mustCall(() => {
w.unref();
}));
// Wait a bit so that the 'message' event is emitted while the Worker exits.
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 100);