Destroy process tree on exec abort#33596
Conversation
Signed-off-by: Jendrik Johannes <jendrik.johannes@gmail.com>
3e889cc to
5c8ae37
Compare
Signed-off-by: Jendrik Johannes <jendrik.johannes@gmail.com>
5c8ae37 to
727131e
Compare
|
Thank you for your proposed contribution! This PR has a valid DCO and tests. The relevant team for this area will confirm the design of the implementation choices. |
| execHandle.waitForFinish().exitValue != 0 | ||
| } | ||
|
|
||
| @Requires(UnitTestPreconditions.Jdk8OrEarlier) |
There was a problem hiding this comment.
Unit tests no longer run on anything below Java 17, so this will never run. We need an integration test to exercise this properly on Windows.
There was a problem hiding this comment.
I added an integration test for the use case the feature solves. Unfortunately, it only runs on Unix, as I did not find a fixture for testing it on Windows. This also screams flakiness.
As this change has no Windows specific code on the Gradle side, I think is is fine though. And the code is tested on Windows in the unit test. I don't think in this case an integration test adds much. It's executing the same code path.
Regarding the test above I now removed: I am not sure how to get code to even execute on Java 8. So I did not any replacement.
If you think there should be additional tests, please advice what exactly we should add.
There was a problem hiding this comment.
Fixed this and added integration tests for Windows
There was a problem hiding this comment.
Thank you @asodja for picking this up. Much appreciated. 🙇
Signed-off-by: Jendrik Johannes <jendrik.johannes@gmail.com>
Signed-off-by: Jendrik Johannes <jendrik.johannes@gmail.com>
Signed-off-by: Jendrik Johannes <jendrik.johannes@gmail.com>
|
this should get merged |
|
I will take it from here and take care that it gets in 9.1.0. |
|
|
||
| package org.gradle.integtests.fixtures | ||
|
|
||
|
|
| return getProcessHandle(pid) | ||
| } | ||
|
|
||
| private static def getProcessHandle(Long pid) { |
There was a problem hiding this comment.
This should be marked with @Nullable
| private DaemonClientFixture client | ||
| private int daemonLogCheckpoint | ||
|
|
||
| @Requires(UnitTestPreconditions.Jdk9OrLater) |
There was a problem hiding this comment.
This should not be necessary. All integ tests run on 17+
|
i backported this on top of 8.14 since too many plugins don't support 9 yet, i hope you guys will too |
046d94a to
4631b1e
Compare
Co-authored-by: Justin <jvandort@gradle.com>
4631b1e to
728fc34
Compare
|
@doctorpangloss I am not sure if we will backport this, technically 8.x line is only in maintenance mode. We will discuss it internally |
|
@doctorpangloss yes, this kind of fix would be a good value add to backport. Well, replied too fast, the code here has the right safeguards against that. |
|
@jjohannes Thank you for your contribution! |
What a mess. See: - [Terminating Gradle build does not execute finalizedBy task](gradle/gradle#13212) - [`finalizedBy` does not work when task fails and the target task depends on origin task](gradle/gradle#27707) - [Finalizer tasks are not run when the build is cancelled](gradle/gradle#28399) - [Gradle doesn't stop forked processes](gradle/gradle#7603) - [Stop forked exec and javaexec on build termination](gradle/gradle#18756) - [Destroy process tree on exec abort](gradle/gradle#33596)"
Fixes #7603
New attempt based on #18756
Note
❗ Most of the added lines in this PR is test and test setup code. There is effectively just one line of new productions code:
process.descendants().forEach(java.lang.ProcessHandle::destroy);Context
With Java 9+ Java offers APIs to solve this OS independently. With Gradle 9 (next release), the minimum Java version for running the Gradle daemon is 17. Therefore, a solution that only works for Java 9+ is reasonable.
If the
ExecHandleRunnercode (modified in this PR) runs in a worker process, the old behavior is kept and a message about that is logged on DEBUG level.This PR is following up on a discussion on Slack with @oleg-nenashev and @jvandort.
Contributor Checklist
<subproject>/src/integTest) to verify changes from a user perspective.<subproject>/src/test) to verify logic.[ ] Update User Guide, DSL Reference, and Javadoc for public-facing changes../gradlew sanityCheck../gradlew <changed-subproject>:quickTest.Reviewing cheatsheet
Before merging the PR, comments starting with