Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ext/node): unref pending reads in readStop #27064

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions ext/io/12_io.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ class Stdin {
if (this.#opPromise) {
core.unrefOpPromise(this.#opPromise);
}
// Reset the promise so that it can be re-ref'd.
this.#opPromise = undefined;
}
}

Expand Down
15 changes: 14 additions & 1 deletion ext/node/polyfills/internal_binding/stream_wrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ const SUGGESTED_SIZE = 64 * 1024;
export class LibuvStreamWrap extends HandleWrap {
[kStreamBaseField]?: Reader & Writer & Closer & Ref;

reading!: boolean;
#reading = false;
destroyed = false;
writeQueueSize = 0;
Expand Down Expand Up @@ -146,13 +145,27 @@ export class LibuvStreamWrap extends HandleWrap {
return 0;
}

get reading() {
return this.#reading;
}

set reading(value) {
// no-op
}

/**
* Stop the reading of the stream.
* @return An error status code.
*/
readStop(): number {
this.#reading = false;

// Unref any reads that are pending until this point.
if (this.unref) {
this.unref();
this.ref();
}

return 0;
}

Expand Down
5 changes: 5 additions & 0 deletions tests/specs/node/stdin_pause/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"args": "run -A main.mjs",
"output": "",
"exitCode": 0
}
2 changes: 2 additions & 0 deletions tests/specs/node/stdin_pause/main.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
process.stdin.resume();
process.stdin.pause();
Loading