open-cli-tools / concurrently

Run commands concurrently. Like `npm run watch-js & npm run watch-less` but better.
https://www.npmjs.com/package/concurrently
MIT License
7.13k stars 233 forks source link

Impossible to kill a triggered shell script in Windows #137

Open anselmdk opened 6 years ago

anselmdk commented 6 years ago

Example:

We're having the following inside of our scripts in package.json (I've removed all unnecessary clutter):

"scripts": {
  "test": "concurrently  \"sh ./scripts/development/client.sh\"  --names \"CLIENT\" -c \"blue.bold\" --prefix name --kill-others"
},

The client.sh file looks like this:

#!/bin/sh
source './.env'
./node_modules/.bin/next src/client -p $CLIENT_PORT

Running npm run test works just fine, but stopping the script doesn't stop the triggered shell script nor the javascript script inside of it.

whymarrh commented 6 years ago

You may need to trap SIGTERM in your script and gracefully kill the child processes you've started.

gustavohenke commented 6 years ago

Wow. This was opened some good months ago... I'm sorry for such delay of mine 😞

I'm assuming that the code that listens for SIGINT/SIGTERMs is inherently broken on Windows, as signals don't exist there.

https://github.com/open-cli-tools/concurrently/blob/ba6f25a6c190b321de86e39c73b38d74ec403f01/src/main.js#L286-L292

Some context: https://stackoverflow.com/a/14861513/2083599:

gustavohenke commented 6 years ago

So, some further reading tells me that this may be an issue with old Node.js versions that didn't cope with this Windows limitation.

This reminded me that processes spawned by concurrently on Windows do run in non-detached mode though, so they should be killed when the parent process is terminated.

I will have to do some investigation on this.

thiagodp commented 2 years ago

@gustavohenke

Using GitHub Actions with ubuntu-latest, macos-latest, windows-latest and it fails on windows-latest with Node 12 and 14, but it works with Node 16:

npx concurrently --success=first "npx foo" "(sleep 5 || timeout 5 > NUL) && npx bar"

Notes:

Real output: image

👉 It appears that concurrently is not parsing the arguments correctly for some reason.

RichardBradley commented 1 year ago

This happens for me on Node18 on Windows 10.

Any child processes started by concurrently are not killed when node exits, unless the parent node process was launched in cmd or PowerShell and killed with ctrl+C.

I launch the parent node process from Java or another shell (e.g. Cygwin), and kill that process then all child processes are leaked.

I'm currently working around this by enumerating descendent processes and killing them directly.