Repository navigation
[invalid defect] Cannot exit all the processes when CTRL + C in readline #52597
Copy link
Copy link
Closed
Labels
readlineIssues and PRs related to the built-in readline module.Issues and PRs related to the built-in readline module.
Description
Version
Node v21.6.0
Platform
Microsoft Windows NT 10.0.22621.0 x64
Subsystem
node:readline
What steps will reproduce the bug?
- I'm using this code to apply 2 ways of SIGINT, process SIGINT and readline SIGINT
// Import the readline module to mock user interactions via the console.
const readline = require('readline');
// Mock the client and its dependencies with basic stubs.
class Client {
async sendRequest(url: string) {
return 'Response from ' + url; // Dummy response
}
}
// Function to simulate response conversion from gemtext.
function fromGemtext(response: string) {
return response; // Simply return the same dummy response for simplicity
}
const client = new Client();
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
process.on('SIGINT', function () {
console.log('Graceful shutdown');
process.exit(0);
}).on('SIGINT', function () {
process.emit('SIGINT');
});
process.on('SIGINT', function () {
// graceful shutdown
process.kill(process.pid, 'SIGINT');
});
// Versioning for the dummy package.
const version = '1.0.0'; // Hardcoded version
console.log(`Dummy Client v${version}`);
console.log("Dummy CLI for testing. Type '/c' to exit or any URL to simulate a request.");
// Function to handle the "gemini" requests in a dummy manner.
async function handleGeminiRequest(inputUrl: string) {
try {
const response = await client.sendRequest(inputUrl);
console.log(fromGemtext(response));
} catch (err) {
if (err instanceof Error)
console.log('Error:', err.message);
}
}
// Function to create commands.
function createCommands(string: string) {
if (string.trim() === '/c') {
return 'exit';
}
return 'url-request'; // Default to URL request for any other input
}
// Function to prompt and process commands.
function promptAndProcessCommand() {
console.log(`Platform ${process.platform}, Node ${process.version}, isTTY? ${process.stdout.isTTY}`);
if (process.platform === "win32") {
rl.on("SIGINT", function () {
console.log("Process terminated (SIGINT).");
process.kill(process.pid, 'SIGINT');
});
}
rl.question('> ', async (cmd: string) => {
const command = createCommands(cmd);
switch (command) {
case 'exit':
console.log('Bye!');
rl.close();
process.exit(0);
case 'url-request':
await handleGeminiRequest(cmd);
promptAndProcessCommand(); // Continue the command loop
break;
}
});
}
// Start the command loop.
promptAndProcessCommand();- run the code
- when
>is visible try to pressCTRL + C
How often does it reproduce? Is there a required condition?
N/A. not a flaky bug.
What is the expected behavior? Why is that the expected behavior?
When I press CTRL + C it should exit my program gracefully
What do you see instead?
I need to press Enter after CTRL + C
Additional information
Related:
- SIGINT not triggering with readline #4758
- Have to send two SIGINT to kill when prompt is open SBoudrias/Inquirer.js#293 (Ticket closed as stale)
- Ctrl+C during np cli exits with status 0 sindresorhus/np#528 (Demanding inquirer to fixes it, when I track all the issues, the issue is coming from how
node:readlinecore works, correct me if I'm wrong.)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
readlineIssues and PRs related to the built-in readline module.Issues and PRs related to the built-in readline module.
Activity
[-]SIGINT not working for me[/-][+]Cannot exit all the processes when `CTRL + C` in readline [/+]avivkeller commentedon Apr 20, 2024
Hi, thanks for the bug report! I'm unable to reproduce this on Kali Linux in NodeJS v21.7.3. Could you try using the latest version of NodeJS and let me know if this issue still occurs?
fzn0x commentedon Apr 20, 2024
Hi, it is still not working as expected in
Microsoft Windows NT 10.0.22621.0 x64even with the latest version21.7.3.avivkeller commentedon Apr 20, 2024
Hmm, I'll take a look
fzn0x commentedon Apr 20, 2024
@redyetidev I resolved the issue. I'm using a custom Node command and attempted to integrate some Bun code into the core, which led to this defect. Therefore, the defect originated from Bun. Thank you again for your attention!
I will open ticket there instead. and
ssstDon't tell everyone, Node.js is the most stable Javascript Runtime engine in the Ecosystem now ;) This was my mistake.[-]Cannot exit all the processes when `CTRL + C` in readline [/-][+][invalid defect] Cannot exit all the processes when `CTRL + C` in readline [/+]