-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: #33394 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
Showing
2 changed files
with
18 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
test/parallel/test-worker-unref-from-message-during-exit.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'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); |