Skip to content

[invalid defect] Cannot exit all the processes when CTRL + C in readline  #52597

Description

@fzn0x

Version

Node v21.6.0

Platform

Microsoft Windows NT 10.0.22621.0 x64

Subsystem

node:readline

What steps will reproduce the bug?

  1. 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.constreadline=require('readline');// Mock the client and its dependencies with basic stubs.classClient{asyncsendRequest(url: string){return'Response from '+url;// Dummy response}}// Function to simulate response conversion from gemtext.functionfromGemtext(response: string){returnresponse;// Simply return the same dummy response for simplicity}constclient=newClient();constrl=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 shutdownprocess.kill(process.pid,'SIGINT');});// Versioning for the dummy package.constversion='1.0.0';// Hardcoded versionconsole.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.asyncfunctionhandleGeminiRequest(inputUrl: string){try{constresponse=awaitclient.sendRequest(inputUrl);console.log(fromGemtext(response));}catch(err){if(errinstanceofError)console.log('Error:',err.message);}}// Function to create commands.functioncreateCommands(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.functionpromptAndProcessCommand(){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)=>{constcommand=createCommands(cmd);switch(command){case'exit':
console.log('Bye!');rl.close();process.exit(0);case'url-request':
awaithandleGeminiRequest(cmd);promptAndProcessCommand();// Continue the command loopbreak;}});}// Start the command loop.promptAndProcessCommand();
  1. run the code
  2. when > is visible try to press CTRL + 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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    readlineIssues and PRs related to the built-in readline module.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions