-
Notifications
You must be signed in to change notification settings - Fork 30k
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
readline hangs the process on Win10 #31762
Comments
Unable to reproduce using Command Prompt and Powershell. Able to reproduce using MinTTY with all versions of Node.js. It may be a MinTTY issue rather than Node.js issue. It works if Node.js is invoked as |
While I too can't reproduce this exact same issue (OP's code) but I'm seeing similar issue in enquirer/enquirer#245. The workaround (wrapping I can reproduce in default Windows CMD, and PowerShell. |
There does not appear to be any bug here as the behavior is expected, but there can definitely be some API improvements to be made here. |
execute |
const oldClose = readline.Interface.prototype.close
readline.Interface.prototype.close = function () {
this.terminal = false
oldClose.call(this)
}; |
Node 14.6 has fixed this problem. |
Sweet! I hade a look at the change log (https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V14.md#14.6.0) But nothing caught my eye. Do you know what changed fixed the problem? |
I don`t know the reason but this problem hasn`t appeared since upgrading node from 14.5 to 14.6.
This problem first appeared in version 10.2, and there are no related changes in the change log too.
…------------------ 原始邮件 ------------------
发件人: "nodejs/node" <notifications@github.com>;
发送时间: 2020年8月13日(星期四) 下午5:17
收件人: "nodejs/node"<node@noreply.github.com>;
抄送: "710959013"<chengzhuo5@qq.com>;"Comment"<comment@noreply.github.com>;
主题: Re: [nodejs/node] readline hangs the process on Win10 (#31762)
Node 14.6 has fixed this problem.
Sweet! I hade a look at the change log (https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V14.md#14.6.0) But nothing caught my eye. Do you know what changed fixed the problem?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Can confirm. My above issue seems to have been resolved with Node v14.8.0 |
It`s related to this commit: libuv/libuv@aeab873 |
## discussion Node-v10.2 through Node-v14.6 contain a bug which may cause an application freeze on Windows platforms when 'readline' is closing (see discussion at <nodejs/node#31762>). As a work-around, using... ``` const readlineOldClose = readline.Interface.prototype.close; readline.Interface.prototype.close = function () { this.terminal = false; readlineOldClose.call(this); }; ``` seems to fix the issue without any obvious negative side effects. ref: <enquirer/enquirer#245> ref: <nodejs/node#31762>
Still not working correctly.
cli.js #!/usr/bin/env node
const readline = require("readline")
;(async () => {
const stdin = readline.createInterface({ input: process.stdin })
for await (const line of stdin) {
console.log(line)
}
})() echo 'ok' | node cli.js
# ok
echo 'ok' | the-bin-field-in-package-json
# hang It seems to be a duplicate of this issue. |
I can reproduce this pretty consistently (90% of the time) using the following code. Tested on Node.js v16.17.1: import readline from 'readline';
import { setTimeout } from 'timers/promises';
const block = () => {
const r = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
return () => {
console.log('unblock');
r.close();
};
};
(async () => {
const blockA = block();
await setTimeout(10);
blockA();
await setTimeout(10);
block()();
})().catch(() => {}); As suggested in the comments above, I've been able to unblock it by setting const block = () => {
const r = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
return async () => {
console.log('unblock');
await setTimeout(0);
r.terminal = false;
r.close();
};
}; |
What steps will reproduce the bug?
Running the above relying on the hash-bang/she-bang,
./readline.js
, will make it hang.Running the above using node,
node readline.js
, everything works as expectedHow often does it reproduce? Is there a required condition?
Always
What is the expected behavior?
The program should exit back to the shell after the user has pressed Enter
What do you see instead?
The program hangs and I can't kill it either by Ctrl+D nor Ctrl+C
Additional information
A workaround is to wrap the
close()
call in asetTimeout
like soThis comment is similar, but that one states that it works in Win 10. That is not my experience.
#17495 (comment)
The text was updated successfully, but these errors were encountered: