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

readline: readline.close() result in process.stdout is unexpected #30701

Closed
supperchong opened this issue Nov 28, 2019 · 6 comments
Closed

readline: readline.close() result in process.stdout is unexpected #30701

supperchong opened this issue Nov 28, 2019 · 6 comments
Labels
readline Issues and PRs related to the built-in readline module. windows Issues and PRs related to the Windows platform.

Comments

@supperchong
Copy link

supperchong commented Nov 28, 2019

  • Version: v12.13.0
  • Platform: 64-bit (Windows)
  • Subsystem:
const readline = require("readline");

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
setTimeout(() => {
    rl.close();
}, 1000);
setInterval(() => {
    console.log('test')
}, 1000);

win10 output(empty)

linux output

test
test
...
const readline = require("readline");
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

setTimeout(() => {
  rl.close();    // process.stdin.isRaw =false
  process.stdin.setRawMode(true); //stop at here
  console.log("asd");
}, 1000);

this code will block without any error

@supperchong
Copy link
Author

supperchong commented Nov 28, 2019

  1. look at the source code ,if replace rl.close() with process.stdin.pause(); process.stdin.setRawMode(false);, the output is the same (win10 empty)
//test.js
const readline = require("readline");

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

setTimeout(() => {
  process.stdin.pause();
  process.stdin.setRawMode(false);

  setInterval(() => {
    console.log("test");
  }, 1000);
}, 1000);
  1. if change console.log to fs.writeFileSync ,it is ok.
  2. But if add both console.log and fs.writeFileSync , the process seems like block after console.log
const readline = require("readline");
const fs = require("fs");
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

setTimeout(() => {
  process.stdin.pause();
  process.stdin.setRawMode(false);

  setInterval(() => {
    fs.writeFileSync("./temp", "test2", { flag: "a" });
    console.log("test");
  }, 1000);
}, 1000);

terminal output is empty,file ./temp only has one string test2

 $ cat ./temp
 $ test2

I have looked at the docs,but I'm still confused with these result. Or if these are not bug, what is the recommend way to repeat use readline.createInterface and close readline ?

@devsnek devsnek added the readline Issues and PRs related to the built-in readline module. label Dec 3, 2019
@Fishrock123 Fishrock123 added the windows Issues and PRs related to the Windows platform. label Dec 13, 2019
@chengzhuo5
Copy link

execute rl.terminal = false before rl.close()can solve this problem.
#31762

@chengzhuo5
Copy link

Node 14.6 has fixed this problem.

@Hakerh400
Copy link
Contributor

Bisected to a9ca420 (precisely libuv/libuv@aeab873). This issue is fixed and should be closed.

@supperchong
Copy link
Author

Nice ! Thanks for the information. @chengzhuo5 @Hakerh400

@Guseyn
Copy link

Guseyn commented May 29, 2022

rl.terminal = false

Better like this:

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
readline Issues and PRs related to the built-in readline module. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

No branches or pull requests

6 participants