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

Fix Ctrl-C handling #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

rhpijnacker
Copy link

Fixes #80 .

When installing a custom SIGINT handler, the default handler is removed.
This means that the process's exit() will not be called.

This is demonstrated fairly simply with this program:

process.on('exit', function () { console.log('onexit'); });
process.on('SIGINT', function () { console.log('SIGINT'); });
                                 
setTimeout(function() { console.log('time\'s up'); }, 5000);

Adding process.exit(1) in the SIGINT handler fixes this.

@jason0x43
Copy link
Member

The SIGINT handlers should ensure that all timers are stopped, child processes are killed, sockets are closed, etc, so that Intern can quit gracefully. Calling process.exit from a SIGINT handler will exit immediately, preventing any other SIGINT handlers in the rest of Intern from running, so we don't really want to do that.

The trick is to figure out what socket/timer/etc. is keeping the node process alive and to ensure that gets killed.

@rhpijnacker
Copy link
Author

From what I've seen, calling process.exit will trigger all onexit handlers.
So we can use that to kill the children etc.

The example pasted above shows quite simply that once a SIGINT handler is installed, the default exit handler will not be called. I tested as much on Windows and Mac.

Also the node-js documentation states:

'SIGTERM' and 'SIGINT' have default handlers on non-Windows platforms that reset the terminal mode before exiting with code 128 + signal number. If one of these signals has a listener installed, its default behavior will be removed (Node.js will no longer exit).

This matches quite well with the behaviour I'm seeing.

@jason0x43
Copy link
Member

Calling process.exit will trigger exit handlers, but it won't wait around for them to complete if any async operations need to happen. The reason Intern intercepts SIGINT at all is to prevent the immediate exit so that everything can shut down gracefully.

The root problem is that that some timer isn't being canceled or Promise isn't being resolved when SIGINT occurs, so a process is staying alive. Ideally, we should figure out what isn't being killed and make sure that it is. If that turns out to be impossible, calling exit may be the way to go, but I'd prefer to save that as a last resort.

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

Successfully merging this pull request may close these issues.

Ctrl-C leaves process running
2 participants