forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
worker: avoid potential deadlock on NearHeapLimit
It can happen that the `NearHeapLimit` callback is called while calling the `oninit()` function on `MessagePort` construction causing a deadlock when the `Worker::Exit()` method is called, as the `mutex_` was already held on the `CreateEnvMessagePort()` method. To fix it, just use the `mutex_` to protect the `child_port_data_` variable and avoid holding it when creating the `MessagePort`. Also, return early from `Worker::Run()` if the worker message port could not be created. Fixes: nodejs#38208
- Loading branch information
1 parent
8780537
commit b9cd8b9
Showing
3 changed files
with
37 additions
and
5 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
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
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,22 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const worker_threads = require('worker_threads'); | ||
|
||
const opts = { | ||
eval: true, | ||
resourceLimits: { | ||
maxYoungGenerationSizeMb: 0, | ||
maxOldGenerationSizeMb: 0 | ||
} | ||
}; | ||
|
||
const worker = new worker_threads.Worker('str', opts); | ||
const arr = []; | ||
for (let i = 0; i < 15000000; ++i) { | ||
arr.push('num.' + i); | ||
} | ||
|
||
worker.on('error', common.mustCall((err) => { | ||
assert.strictEqual(err.code, 'ERR_WORKER_OUT_OF_MEMORY'); | ||
})); |