Kill NpmTask when gradle is stopped
Hi, first of all thanks for a great gradle plugin.
One of my tasks in gradle starts an infinite node task called watch. This task is infinite it means it stops on Ctrl + c. Unfortunately when I kill gradle task the SIGKILL does not propagate to the npm task.
task watchWeb(type: NpmTask, dependsOn: ["installNpmModules"]) {
args = ["run", "watch"]
}
Terminal execution:
./gradlew watchWeb
<Ctrl+c>
ps aux | grep node
<node task is still running>
Could you tell how to propagate the SIGKILL to npm task?
This issue affects Grails 3.3.0 Angular projects when executed with client:bootRun. After the server is started via the gradle task, stopping the gradle task with Ctrl+C does not stop the node.exe process.
The next time I go to start up the server, I get the "port is already in use" error.
See: https://github.com/grails-profiles/angular/issues/12
Just to summarize it. There is a workaround for this problem described in https://github.com/srs/gradle-node-plugin/issues/143#issuecomment-328406484
./gradlew watchWeb --no-daemon
<Ctrl+c>
ps aux | grep node
<node task is not running>
...although IMHO it's a workaround not a solution. That is why I do not close this issue.
@mendlik this seems to be a limitation of Gradle daemon (gradle/gradle#1128) and I do not believe this can be fixed within the plugin. Maybe we could communicate the impact to the Gradle team to motivate them to provide a solution here.
@orange-buffalo good idea. I have just created a topic on gradle discuss. Let's start there.
any update on this issue ?
With Gradle 4.8 it should now be possible to fix this issue by implementing the Cancellable Interface: https://github.com/gradle/gradle/pull/5206
This bothers us on the CI server (GitLab CI, but it does not matter I guess). If we cancel the build when the Node plugin is running already, it will finish the build anyway. While Gradle does not kill it, CI server waits for it and any next build is pending for many minutes. And we run the builds with --no-daemon, but it does not help in our case - it seems like there is still this one-off daemon: "Daemon will be stopped at the end of the build stopping after processing"
Same here. We are running a server using an NPM script (npm start). Even by setting --no-daemon the server keeps running after CTRL+C'ing out. A fix for this would be higly appreciated!
any update ?
If anyone is interested in creating a solution to this there's further context in https://github.com/node-gradle/gradle-node-plugin/issues/65#issuecomment-581840403
But this is something that should be fixed in Gradle and with Java 9+ it's supposedly easy to do.
I also recently encountered this issue and I made a custom workaround based on Gradle Shared Build Services (https://docs.gradle.org/current/userguide/build_services.html). The idea is that the service is attached to npm tasks and kills them properly (i.e. also killing dependents processes) in case the Gradle task is stopped. If it may be of any use to someone else, I made a small Gradle plugin for it https://github.com/PeredurOmega/GradleNpmPlugin mainly resolving this issue + automatically defining tasks for scripts defined in package.json.