concurrently icon indicating copy to clipboard operation
concurrently copied to clipboard

Impossible to kill a triggered shell script in Windows

Open anselmdk opened this issue 6 years ago • 5 comments

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.

anselmdk avatar Mar 27 '18 12:03 anselmdk

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

whymarrh avatar Aug 02 '18 12:08 whymarrh

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 avatar Aug 13 '18 01:08 gustavohenke

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.

gustavohenke avatar Aug 13 '18 02:08 gustavohenke

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

  • foo and bar are hypothetical applications
  • argument --success does not matter - same problem occurs using it or not

Real output: image

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

thiagodp avatar Jan 12 '22 23:01 thiagodp

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.

RichardBradley avatar Jun 23 '23 20:06 RichardBradley