@@ -3,7 +3,6 @@ package datadog.smoketest
33import datadog.trace.agent.test.utils.PortUtils
44import java.nio.file.Files
55import java.nio.file.Paths
6- import java.util.concurrent.TimeoutException
76import spock.lang.AutoCleanup
87import spock.lang.Shared
98import spock.lang.Specification
@@ -108,32 +107,45 @@ abstract class ProcessManager extends Specification {
108107 }
109108
110109 def cleanupSpec () {
110+ Throwable firstFailure = null
111111 testedProcesses. each { tp ->
112- int maxAttempts = 10
112+ if (tp == null ) {
113+ return // closure continue — skip null slots
114+ }
115+
113116 Integer exitValue
114- for (int attempt = 1 ; attempt <= maxAttempts != null ; attempt++ ) {
115- try {
116- exitValue = tp?. exitValue()
117- break
117+ try {
118+ exitValue = tp. exitValue()
119+ } catch (Throwable ignored) {
120+ System . out. println (" Destroying instrumented process" )
121+ tp. destroy()
122+
123+ if (! tp. waitFor(5 , TimeUnit . SECONDS )) {
124+ System . out. println (" Destroying instrumented process (forced)" )
125+ tp. destroyForcibly()
126+ tp. waitFor(10 , TimeUnit . SECONDS )
118127 }
119- catch (Throwable ignored) {
120- if (attempt == 1 ) {
121- System . out. println (" Destroying instrumented process" )
122- tp. destroy()
123- }
124- if (attempt == maxAttempts - 1 ) {
125- System . out. println (" Destroying instrumented process (forced)" )
126- tp. destroyForcibly()
128+
129+ try {
130+ exitValue = tp. exitValue()
131+ } catch (Throwable ignoredAgain) {
132+ // Process did not exit even after SIGKILL — record failure but continue
133+ // cleaning up any remaining processes before propagating.
134+ def failure = new RuntimeException (" Instrumented process failed to exit after SIGKILL" )
135+ if (firstFailure == null ) {
136+ firstFailure = failure
137+ } else {
138+ firstFailure. addSuppressed(failure)
127139 }
128- sleep 1_000
140+ return // closure continue
129141 }
130142 }
131143
132- if (exitValue != null ) {
133- System . out . println ( " Instrumented process exited with " + exitValue)
134- } else if (tp != null ) {
135- throw new TimeoutException ( " Instrumented process failed to exit " )
136- }
144+ System . out . println ( " Instrumented process exited with " + exitValue)
145+ }
146+
147+ if (firstFailure != null ) {
148+ throw firstFailure
137149 }
138150 }
139151
0 commit comments