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

Gradle doesn't correctly kill subprocesses on interrupt on Windows. It should. #18716

Closed
doctorpangloss opened this issue Oct 20, 2021 · 3 comments
Labels
closed:duplicate Duplicated or superseeded by another issue

Comments

@doctorpangloss
Copy link

doctorpangloss commented Oct 20, 2021

  1. Use Windows.
  2. Open a console of any kind, in any Windows environment - cmd, powershell or the bash that ships with git.
  3. Start a gradle task with an exec that never finishes.
  4. Hit Ctrl+C or any preferred interrupt method.
  5. Observe the process started by exec is not terminated.

Numerous people report issues related to this: #7603 #6114 #3093 #1128 #1109

I fixed this issue in NuProcess - brettwooldridge/NuProcess#133 - which you should use instead of ProcessBuilder on Windows. You will need to ping them to merge my PR.

You can trap Ctrl+C and use it to kill the subprocesses using NuProcess, or permit Ctrl+C to kill the daemon and using NuProcess, result in the child processes being terminated correctly.

Otherwise, Gradle is working really great for me.

@ljacomet ljacomet added in:invoking-gradle Running Executing re:windows Issue related to using Gradle on Windows and removed to-triage labels Oct 22, 2021
@ljacomet
Copy link
Member

Thanks for your interest in Gradle!

Could you please improve the title and description of the issue to be less passive-aggressive please?

@doctorpangloss doctorpangloss changed the title It's 2021. Gradle (really, everything) doesn't correctly kill subprocesses on interrupt on Windows. It should. Gradle doesn't correctly kill subprocesses on interrupt on Windows. It should. Oct 22, 2021
vlsi added a commit to vlsi/gradle that referenced this issue Apr 9, 2022
Terminating a single process does not terminate its children automatically,
so when Gradle terminates .bat file, it leaves the forked application running.

The problem is often visible as "process exec process keeps running after build termination".
The root cause is that in Windows exec uses cmd -> process.exe sequence,
so aborting the build terminates "cmd.exe", and "process.exe" keeps running.

The workaround is to use taskkill /PID $pid /T /F command that terminates the process tree

For other operating systems, alternative solutions are needed.
This commit uses Process#descendants if Gradle runs with Java 9+
Otherwise it resorts to the previous "process.destroy" sequence.

fixes gradle#18716 gradle#7603 gradle#6114 gradle#3093 gradle#1128 gradle#1109

Signed-off-by: Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. If you're interested in how we try to keep the backlog in a healthy state, please read our blog post on how we refine our backlog. If you feel this is something you could contribute, please have a look at our Contributor Guide. Thank you for your contribution.

@github-actions github-actions bot added the stale label Oct 22, 2022
@ov7a
Copy link
Member

ov7a commented Jul 26, 2023

Sorry for the late reply!

Thank you for your interest in Gradle!

This issue will be closed as a duplicate of

Please add your use case and 👍 to that issue.


#7603 has a PR with a fix. Unfortunately, we don't have the capacity to push it right now, but it is in the backlog of the relevant team.

@ov7a ov7a closed this as not planned Won't fix, can't repro, duplicate, stale Jul 26, 2023
@ov7a ov7a added closed:duplicate Duplicated or superseeded by another issue and removed a:bug re:windows Issue related to using Gradle on Windows stale in:invoking-gradle Running Executing labels Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed:duplicate Duplicated or superseeded by another issue
Projects
None yet
Development

No branches or pull requests

3 participants