-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
worker: perform initial port.unref() before preload modules
The refcount of the internal communication port is relevant for stdio, but the `port.unref()` call effectively resets any `.ref()` calls happening during stdio operations happening before it. Therefore, do the `.unref()` call before loading preload modules, which may cause stdio operations. Fixes: #31777 PR-URL: #33455 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
- Loading branch information
1 parent
3b46e7f
commit 1c64bc5
Showing
2 changed files
with
21 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const fixtures = require('../common/fixtures'); | ||
const { Worker } = require('worker_threads'); | ||
const assert = require('assert'); | ||
|
||
// Regression test for https://github.com/nodejs/node/issues/31777: | ||
// stdio operations coming from preload modules should count towards the | ||
// ref count of the internal communication port on the Worker side. | ||
|
||
for (let i = 0; i < 10; i++) { | ||
const w = new Worker('console.log("B");', { | ||
execArgv: ['--require', fixtures.path('printA.js')], | ||
eval: true, | ||
stdout: true | ||
}); | ||
w.on('exit', common.mustCall(() => { | ||
assert.strictEqual(w.stdout.read().toString(), 'A\nB\n'); | ||
})); | ||
} |