forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
worker: only unref port for stdin if we ref’ed it before
We set the `kStartedReading` flag from `_read()` for Worker stdio, and then `ref()` the port. However, the `.on('end')` handler is also attached when `._read()` is not called, e.g. when `process.stdin` inside a Worker is prematurely ended because stdin was not enabled by the parent thread. In that case, we should not call `.unref()` for stdin if we did not also call `.ref()` for it before. Fixes: nodejs#28144
- Loading branch information
Showing
2 changed files
with
24 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
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 assert = require('assert'); | ||
const { Worker, isMainThread } = require('worker_threads'); | ||
|
||
// Regression test for https://github.com/nodejs/node/issues/28144. | ||
|
||
if (isMainThread) { | ||
const w = new Worker(__filename); | ||
w.on('exit', common.mustCall((status) => { | ||
assert.strictEqual(status, 0); | ||
})); | ||
w.stdout.on('data', common.mustCall(10)); | ||
} else { | ||
process.stdin.on('data', () => {}); | ||
|
||
for (let i = 0; i < 10; ++i) { | ||
process.stdout.write(`processing(${i})\n`, common.mustCall()); | ||
} | ||
} |