Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

SIGINT captured #789

Closed
sumarlidason opened this issue Mar 1, 2019 · 5 comments
Closed

SIGINT captured #789

sumarlidason opened this issue Mar 1, 2019 · 5 comments

Comments

@sumarlidason
Copy link

Possibly Related #293

We experienced issues with promises + subprocesses inside the inquirer promise chain when sending SIGINT to the process. Removing the prompt from the process and hardcoded answers resolved the issue. We did some research into what could still be listening for SIGINT from process and found that cli-cursor uses restore-cursor which uses signal-exit. In testing I found that signal-exit's listeners were not being called while sending ctrl-c. Clearing the listeners manually(process.removeAllListeners('SIGINT');) after receiving answers from prompt resolved the issue. We also noticed the event listeners only lingered while using list question type. Here is a sandbox we were testing with:

const i = require('inquirer');
const util = require('util');

const questions = [
  {
    type: 'list',
    name: 'version',
    message: 'Some important question?',
    choices: ["a", "b"],
  }
];

const ask = async () => {
    const answers = await i.prompt(questions);
    const listeners = process.listeners('SIGINT');
    if(listeners.length) {
        console.log(listeners[0].toString());
        console.log(util.inspect(process.listeners('SIGINT')));
    }
};

ask();
@SBoudrias
Copy link
Owner

Are you suggesting we change cli-cursor dependency as it captures the SIGINT?

@sumarlidason
Copy link
Author

It's not so much cli-cursor as signal-exit. signal-exit ensures the cursor is always re-enabled upon process exit. A lot of code to do something so simple. I lack the bandwidth to dig deep -- will revisit. I need to build a sample that reproduces the actual problem.

@shirshak55
Copy link

@sumarlidason what is the issue? I also see ctrl+c don't work with inquirer any more. Is there any good solution?

@sumarlidason
Copy link
Author

@shirshak55 I don't have access to the affected code any more and cannot remember anymore than what is in this issue. Do you have a concise code sample you can share with the problem?

@shirshak55
Copy link

used only

async function getQuestions()=>{
	let questions = await inquirer.prompt({type="list" ...})
	return questions
}

now Ctrl + C is not working on other application lol. especially on express server SIGINT disappears somewhere. And when i remove the above code ctrl +c works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants