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

Have to hit CTRL + c twice to kill run-all in terminal #74

Closed
wonbyte opened this issue Dec 5, 2016 · 13 comments
Closed

Have to hit CTRL + c twice to kill run-all in terminal #74

wonbyte opened this issue Dec 5, 2016 · 13 comments

Comments

@wonbyte
Copy link

wonbyte commented Dec 5, 2016

On macOS Sierra 10.12.1 when I use the npm-run-all in my start script I have to hit ctrl+c twice for it to kill the process. Would expect I can just hit ctrl+c once and that would kill the process.

@mysticatea
Copy link
Owner

mysticatea commented Dec 8, 2016

Thank you for this issue, and I'm sorry that I delayed.

npm-run-all is not handling SIGINT signals on the application layer.
The signals are supposed to send to child processes directly as well.
So some processes which are handling SIGINT signals might be in your npm-scripts.

(I don't have macOS, so I cannot confirm the behavior)

@mysticatea
Copy link
Owner

At least, on Windows, cmd.exe needs ctrl+c twice to kill it.

@rizowski
Copy link

rizowski commented Feb 15, 2017

@mysticatea
I am actually seeing this behavior as well. In my case this only seems to be caused with eslint-watch. If I remove eslint-watch it exits like normal. Problem being, I have verified that eslint-watch is exiting correctly so it seems like the parent process (npm-run-all) is not. Here is the issue that I have been trying to solve: rizowski/eslint-watch#80

I can help with debugging this issue on OSX Sierra.

@jamietre
Copy link

jamietre commented Mar 9, 2017

So - I have spent some time dealing with the windows/CTRL+C issue and would like to help. There are actually other problems: in CMD shells CTRL+C will only kill the parent process. The child processes are detached and must be killed manually. I think most people use git bash, which may handle this better since it uses cygwin process model, but I use TCC/LE (a CMD replacement) and this comes up a lot. I hope nobody actually uses CMD itself, but that also is legitimate and will come up. This is actually a bug with "npm run" itself, too.

So - I have made changes to npm-run-all in my fork that solves this problem and ensures that CTRL+C will be trapped and correctly terminate the child processes. I would like to make a pull request, but I am concerned about the impact my changes would have on non-windows environments or possibly even use cases other than my own basic one (starting parallel tasks from command line).

The specific thing I'm concerned about is that in order for this to work correctly in windows, stdio needs to be "inherit" for the child processes. I'm not very familiar with process spawning in *nix compared to windows - and I don't really understand the purpose of detectStreamKind(stream, std) in lib/run-task.js. So maybe this could just be coded to always use "inherit" for windows O/S, but I suspect there's more going on here (e.g. different invocation mechanisms? ) and I was hoping someone could explain this part of the code.

To sum up the changes generally:

The basic issue in windows is that there's no actual SIGINT signal. So when dealing with child processes, any code that depends on propagating SIGINT won't work. (This includes node spawn). In order to actually capture SIGINT you need to listen on stdin for a SIGINT, and then manually terminate child processes. So - while the shell might correctly terminate the outermost process when you hit CTRL+C, the SIGINT signal doesn't actually do anything when sent to child processes.

Additionally, it is possible for the child process itself to receive the CTRL+C signal rather than the parent process (and I don't understand exactly why this is, but it's easily reproducible) so you also need to handle possible user-initiated terminations of a child process and treat it differently from the process just ending normally or with an error (e.g. - always do an "abort")

@julkue
Copy link

julkue commented Jul 25, 2017

For me, most of the time CTRL + C doesn't even work when calling it multiple times. Need to exit the CMD and reboot sometimes 👎

@stereokai
Copy link

CTRL+C doesn't work at all for me on Win 10

@cassiopagnoncelli
Copy link

Same problem on Mac OS high sierra. Capturing the signals and pass along to the children with 8s auto-exit timeout should solve.

@jbadlato
Copy link

Same problem for me using Git Bash/Windows 7. CTRL+C doesn't abort the processes, and I have to manually end them in task manager.

@bobbwal
Copy link

bobbwal commented Mar 26, 2018

Same for me too, Windows 10/Git bash, CTRL+C doesn't abort the processes and freezes up bash. Attempting to run browser-sync server and watch tasks, not sure if that is relevant.

@eduardoturconi
Copy link

For me, have to hit several times CTRL+C to kill the process.

@corysimmons
Copy link

Been a big proponent of npm-run-all for a long time but in https://github.com/begin-examples/node-create-react-app I have to hold down ctrl + c to get it to eventually terminate. Switched to concurrently and it works fine. 🤷

@sahilrajput03
Copy link

I have use it for twice, but I'm happy with that. :D

@ghost
Copy link

ghost commented Aug 8, 2023

I replaced the start script run-p watch-ts watch-node with npm run watch-ts & npm run watch-node to get proper SIGINT handling here:

{
  "scripts": {
    "prestart": "run-s clean build-ts",
    "start": "npm run watch-ts & npm run watch-node",
    "watch-node": "delay 1 && node --enable-source-maps --watch dist/index.js",
    "watch-ts": "tsc --watch",
    "win-start": "run-p watch-ts watch-node"
  }
}

It's not cross platform, but Windows devs can use the win-start script if they're not using bash.

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

No branches or pull requests