Node: SIGINT not triggering with readline

Created on 19 Jan 2016  路  6Comments  路  Source: nodejs/node

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.

readline

Most helpful comment

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

All 6 comments

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!

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

Yep.
That's what is happening.
It's being discussed in Inquirer.js, here: https://github.com/SBoudrias/Inquirer.js/issues/293#issuecomment-172282009
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();
});

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

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

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

feross picture feross  路  208Comments

thecodingdude picture thecodingdude  路  158Comments

silverwind picture silverwind  路  113Comments

mikeal picture mikeal  路  197Comments

ctavan picture ctavan  路  87Comments