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

Impossible to kill a triggered shell script in Windows #137

Open
anselmdk opened this issue Mar 27, 2018 · 5 comments
Open

Impossible to kill a triggered shell script in Windows #137

anselmdk opened this issue Mar 27, 2018 · 5 comments

Comments

@anselmdk
Copy link

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
Copy link

whymarrh commented Aug 2, 2018

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

@gustavohenke
Copy link
Member

gustavohenke commented Aug 13, 2018

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.

concurrently/src/main.js

Lines 286 to 292 in ba6f25a

['SIGINT', 'SIGTERM'].forEach(function(signal) {
process.on(signal, function() {
children.forEach(function(child) {
treeKill(child.pid, signal);
});
});
});

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

@gustavohenke
Copy link
Member

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
Copy link

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

@RichardBradley
Copy link

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.

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

5 participants