Skip to content

If one task crashes, others keep running #6

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

Closed
JamesMessinger opened this issue Jun 16, 2015 · 11 comments
Closed

If one task crashes, others keep running #6

JamesMessinger opened this issue Jun 16, 2015 · 11 comments
Assignees
Labels

Comments

@JamesMessinger
Copy link

When running multiple tasks simultaneously, if one task crashes, the others continue running, with no easy way to kill them. For example:

"scripts": {
    "runall": "npm-run-all --parallel watch webserver",
    "watch": "gulp watch",
    "webserver": "node server.js"
}

When I run npm run runall, it runs watch and webserver in parallel. Let's say that watch crashes for some reason (exits with a non-zero exit code). When this happens, npm-run-all also exits. But webserver is still running. If I re-run npm run runall, I now get an error because the webserver can't start because the already-running instance is blocking the port number.

It would be nice if when one of the tasks crashes, npm-run-all would kill the other tasks too.

@JamesMessinger
Copy link
Author

FYI - concurrently does this via a --kill-others argument

@mysticatea
Copy link
Owner

Thank you for the report.
I will check it this evening (JST).

@mysticatea mysticatea self-assigned this Jun 17, 2015
@mysticatea mysticatea added the bug label Jun 17, 2015
@mysticatea
Copy link
Owner

I reproduced this issue.
You are right, when one of tasks clashed, npm-run-all --parallel should kill all tasks.

But I wonder, I thought child processes are killed by OS when the parent process exited....

mysticatea added a commit that referenced this issue Jun 17, 2015
mysticatea added a commit that referenced this issue Jun 17, 2015
mysticatea added a commit that referenced this issue Jun 17, 2015
@JamesMessinger
Copy link
Author

Yeah, I'm confused by that as well. I thought the child tasks would automatically get killed, but they don't.

It might be worth looking at the source code for concurrently, since I've noticed that when I force-quit concurrently (via Ctrl+C), it does kill the child processes. Maybe it has something to do with how the processes are launched?

@mysticatea
Copy link
Owner

I tried to send SIGTERM to remained tasks, but.... npm/npm#4603 :(

@mysticatea
Copy link
Owner

Next, I will try to emulate npm run behavior without using npm tomorrow.

@JamesMessinger
Copy link
Author

It sucks that npm has that issue. I wonder how soon they plan to fix it?

Thanks for looking into this. I appreciate it!

mysticatea added a commit that referenced this issue Jun 19, 2015
refs #6

Because npm does not forward signals to child processes, I lookup child
processes of npm, and kill them.
@mysticatea
Copy link
Owner

I published v1.2.6.

On this version, when npm-run-all runs tasks in parallel, if one of tasks exited with an error, npm-run-all kills other tasks.
npm does not forward signals to child process, so npm-run-all tries to find child processes of npm, and send a SIGTERM signal to them.

Its test is here: https://github.com/mysticatea/npm-run-all/blob/v1.2.6/test/parallel.js#L36-58

Please try it!

@JamesMessinger
Copy link
Author

Awesome! Testing it right now....

@JamesMessinger
Copy link
Author

Seems to work pretty well. It's not 100% perfect, but that's to be expected, given the hoops you're having to jump through.

Thanks!!!

@FDiskas
Copy link

FDiskas commented Nov 19, 2020

got this issue again: If I hit CTRL + C it exits to fast - docker-compose does not stops containers but nextjs node server is stopped correctly

    "dev": "npm-run-all -l --race clean --parallel dev:docker dev:next",
    "dev:docker": "docker-compose -f docker-compose-dev.yml up",
    "dev:next": "next",
    "clean": "rimraf .next",
"npm-run-all": "^4.1.5",

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

No branches or pull requests

3 participants