Skip to content

SIGINT not triggering with readline #4758

Description

@felipenmoura

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.

Activity

  1. evanlucas commented on Jan 19, 2016

    @evanlucas
    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!

  2. added
    readlineIssues and PRs related to the built-in readline module.
    on Jan 19, 2016
  3. Fishrock123 commented on Jan 19, 2016

    @Fishrock123
    Contributor

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

  4. felipenmoura commented on Jan 22, 2016

    @felipenmoura
    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();
    });
  5. added
    wontfixIssues that will not be fixed.
    and removed on Jan 22, 2016
  6. Fishrock123 commented on Jan 22, 2016

    @Fishrock123
    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

  7. added and removed
    wontfixIssues that will not be fixed.
    on Jan 22, 2016
  8. addaleax commented on Jul 7, 2016

    @addaleax
    Member

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

  9. bnoordhuis commented on Oct 7, 2016

    @bnoordhuis
    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.

  10. added a commit that references this issue on Jan 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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