Skip to content

node:readline/promises prevents program from terminating #30075

@ollien

Description

@ollien

Version: Deno 2.2.13

Minimal example

import * as readline from "node:readline/promises";

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

  const answer = await rl.question(question);
  rl.close();

  return answer;
}

input("What is your name? ").then(console.log);

I would expect this program to ask for input, print it, and then exit, but instead it hangs after printing. If I press enter a second time, the program terminates.

A similar program with the callback API does not exhibit this behavior

Working, callback based approach
import * as readline from "node:readline";

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

  rl.question(question, (answer) => {
    rl.close();
    callback(answer);
  });
}

input("What is your name? ", console.log);

I've included strace output from running the promise-based program. It appears to be waiting on some kind of input with epoll (though frankly I'm not sure what).

Both of these programs work as I would expect under node, which makes me think it's a deno bug.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions