Skip to content

SIGINT not triggering with readline #4758

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
felipenmoura opened this issue Jan 19, 2016 · 6 comments
Closed

SIGINT not triggering with readline #4758

felipenmoura opened this issue Jan 19, 2016 · 6 comments
Labels
readline Issues and PRs related to the built-in readline module.

Comments

@felipenmoura
Copy link

When using readline, the process.on('SIGINT', ...) is never triggered.
Is that planned, or perhaps a bug?
I searched and did not find other issues about it.

@evanlucas
Copy link
Contributor

Hi @felipenmoura. Thanks for the report. Could you possibly give us a reduced test case with no external dependencies that shows this behavior so we can reproduce? Thanks!

@r-52 r-52 added the readline Issues and PRs related to the built-in readline module. label Jan 19, 2016
@Fishrock123
Copy link
Contributor

@felipenmoura If you are trying to trigger by ctrl+C, that won't work, because readline catches the keys?

@felipenmoura
Copy link
Author

Yep.
That's what is happening.
It's being discussed in Inquirer.js, here: SBoudrias/Inquirer.js#293 (comment)
Inquirer uses realine internally, therefore, who uses it cannot catch the SIGINT!

By the way, a test case:

process.on('SIGINT', function(){
    console.log('oh, you triggered it!');
});

const readline = require('readline');

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

rl.question('What do you think of Node.js? ', (answer) => {
    console.log('Thank you for your valuable feedback, which was:\n', answer);
    rl.close();
});

@Fishrock123 Fishrock123 added wontfix Issues that will not be fixed. and removed unconfirmed labels Jan 22, 2016
@Fishrock123
Copy link
Contributor

So, readline is actually handles it, but only if it thinks it's input is a TTY: https://github.com/nodejs/node/blob/master/lib/readline.js#L693-L701

@addaleax
Copy link
Member

addaleax commented Jul 7, 2016

Adding the SIGINT listener on the readline instance itself instead of process should work?

@bnoordhuis
Copy link
Member

This looks to have been solved for some time now so I'll go ahead and close the issue. Holler if it should be reopened.

harrysarson added a commit to physical-computation/narvie that referenced this issue Jan 21, 2019
Previous readline would catch cntl-c the first time it was pressed.
Refs: nodejs/node#4758
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
readline Issues and PRs related to the built-in readline module.
Projects
None yet
Development

No branches or pull requests

6 participants