Sitelet https://github.com/nodejs/node/issues/60344
Skip to content

readline/promises question results in unsettled top-level await when reading script from stdin #60344

Description

@mb21

Version

v25.0.0 (also reproduced in v24.9.0)

Platform

Darwin Kernel Version 24.6.0: Mon Aug 11 21:16:52 PDT 2025; root:xnu-11417.140.69.701.11~1/RELEASE_ARM64_T8112 arm64

Subsystem

node:readline/promises

What steps will reproduce the bug?

Place this in test.js:

import { stdin, stdout } from "node:process";
import { createInterface } from "node:readline/promises";

const rl = createInterface({ input: stdin, output: stdout });
const answer = await rl.question("hi\n");
console.log(answer);

and run it with:

cat test.js | node

the above is important. node test.js works fine.

How often does it reproduce? Is there a required condition?

Always.

What is the expected behavior? Why is that the expected behavior?

Program does not terminate.

What do you see instead?

Program terminates with exit code 13 and prints:

hi
Warning: Detected unsettled top-level await at file:///Users/me/test/[eval1]:5
const answer = await rl.question("hi");

Additional information

This seems related, but in my case I don't hit Ctrl-C: #53497

Activity

  1. changed the title [-]Promise readline question results in unsettled promise[/-] [+]Promise readline question results in unsettled promise when reading script from stdin[/+] on Oct 21, 2025
  2. changed the title [-]Promise readline question results in unsettled promise when reading script from stdin[/-] [+]readline/promises question results in unsettled top-level await when reading script from stdin[/+] on Oct 21, 2025
  3. aduh95 commented on Oct 22, 2025

    @aduh95
    Contributor

    What is the expected behavior? Why is that the expected behavior?

    Program does not terminate.

    Why is that the expected behavior? What do you expect instead?

  4. mb21 commented on Oct 22, 2025

    @mb21
    Author

    @aduh95 Why do I expect the program to not terminate? Because the example is pretty much verbatim from https://nodejs.org/api/readline.html#readline where it says:

    Once this code is invoked, the Node.js application will not terminate until the readline.Interface is closed

    Again, this happens only with cat test.js | node. So I imagine there's a bug in the stdin/eval handling somewhere.

    Edit: ah, or do you think this doesn't work because stdin is already used to read in the script so I cannot use it anymore from the script itself?

  5. aduh95 commented on Oct 22, 2025

    @aduh95
    Contributor

    cat closes the stdin once it has read all the files you passed to it, so to me it seems to be working as expected. To clarify, cat test.js | node pipes the stdout of cat test.js into the stdin of node; if you try to re-use stdin from within node, you would find only the script you're trying to run (which is already closed by the time node runs the code since it needs to parse the full source before eval).

  6. mb21 commented on Oct 22, 2025

    @mb21
    Author

    Ah, I'd sort of hoped I could use this to run an interactive installation wizard like curl https://mywebsite.com/install.js | node. But seems I'll just have to use npx then if this is not something node's stdin handling allows. Thanks, feel free to close this then.

  7. aduh95 commented on Oct 22, 2025

    @aduh95
    Contributor

    If you run curl https://mywebsite.com/install.js | node and input stuff in the terminal, it's going to curl's stdin, not node's. There's nothing special about Node.js btw, it's just how piping works in POSIX-complient systems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions