-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Promise readline question results in unsettled promise on abortion #53497
Comments
More Additional InformationAccording to the Nodejs documentation related to exit codes:
In the example below I expect to get import { createInterface } from "node:readline/promises";
process.on("exit", (code) => {
console.log("\nexit:", code);
});
process.on("beforeExit", (code) => {
console.log("\nbeforeExit:", code);
});
process.on("warning", (w) => {
console.log("\nwar :", w);
});
const rl = createInterface({ input: process.stdin, output: process.stdout });
await rl.question("Enter something:"); Result : Enter something:
beforeExit: 0
exit: 0
Warning: Detected unsettled top-level await at file:///home/imanhpr/Desktop/sandbox/node-box/sig.js:16
const data = await rl.question("Enter something:"); It's good to mention when I check the previous process exit code with |
I could try to work on this. Can someone assign me? |
Hi! If you have a solution, feel free to submit a PR! |
Hi, just ran across this; funny thing is, |
@jahudka Can you share a code snippet? |
@DanielVenable sure thing, this is a minimal example which demonstrates what happens: import { createInterface } from 'node:readline/promises';
import { stdin, stdout } from 'node:process';
const rl = createInterface({ input: stdin, output: stdout });
const ctrl = new AbortController();
process.on('SIGINT', function handleSignal() {
console.log(`This should be printed when you press Ctrl+C, but it won't be`);
process.off('SIGINT', handleSignal);
ctrl.abort();
});
try {
const response = await rl.question('Press Ctrl+C now!', { signal: ctrl.signal });
console.log('This is never reached if you press Ctrl+C');
} catch {
console.log('And neither is this');
}
console.log('Nor this');
rl.close(); shove that into a
|
@jahudka It is not |
@DanielVenable Oh, wow, okay, makes sense. Never would've guessed that Readline would mess with signal handling like that.. But seeing the docs now and the fact that it handles Anyway, I've just confirmed that if you install a So as far as I'm concerned, this could maybe do with a big fat warning in the docs, but otherwise I'd say it's working as intended. Thanks for helping me debug! |
Fixes: #53497 PR-URL: #54030 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]>
Version
v22.2.0
Platform
Linux LX-LAPII 6.9.3-arch1-1 #1 SMP PREEMPT_DYNAMIC Fri, 31 May 2024 15:14:45 +0000 x86_64 GNU/Linux
Subsystem
node:readline/promises
What steps will reproduce the bug?
It is not possible to properly handle a user's abortion of a promise readline question with SIGINT or Ctrl+D while rl.question waits for user input:
How often does it reproduce? Is there a required condition?
Every time when a prompt is aborted with Ctrl+C or Ctrl+D.
What is the expected behavior? Why is that the expected behavior?
The expected behavior is to settle a promise on a readline close event, as shown in the following snippet:
What do you see instead?
The promise remains unsettled, resulting in a warning that cannot be caught:
Additional information
This issue is opened based on the discussion in [stackoverflow] How to properly abort Node readline promise question?
The text was updated successfully, but these errors were encountered: