Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ out/

# Others #
##########
/dumps
/logs/*
/bin
/out
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package datadog.smoketest
import datadog.trace.agent.test.utils.PortUtils
import java.nio.file.Files
import java.nio.file.Paths
import java.util.concurrent.TimeoutException
import java.util.concurrent.TimeUnit
import spock.lang.AutoCleanup
import spock.lang.Shared
import spock.lang.Specification
Expand Down Expand Up @@ -108,32 +108,45 @@ abstract class ProcessManager extends Specification {
}

def cleanupSpec() {
Throwable firstFailure = null
testedProcesses.each { tp ->
Comment thread
AlexeyKuznetsov-DD marked this conversation as resolved.
int maxAttempts = 10
if (tp == null) {
return // closure continue — skip null slots
}

Integer exitValue
for (int attempt = 1; attempt <= maxAttempts != null; attempt++) {
try {
exitValue = tp?.exitValue()
break
try {
exitValue = tp.exitValue()
} catch (Throwable ignored) {
System.err.println("Destroying instrumented process")
tp.destroy()

if (!tp.waitFor(5, TimeUnit.SECONDS)) {
System.err.println("Destroying instrumented process (forced)")
tp.destroyForcibly()
tp.waitFor(10, TimeUnit.SECONDS)
}
catch (Throwable ignored) {
if (attempt == 1) {
System.out.println("Destroying instrumented process")
tp.destroy()
}
if (attempt == maxAttempts - 1) {
System.out.println("Destroying instrumented process (forced)")
tp.destroyForcibly()

try {
exitValue = tp.exitValue()
} catch (Throwable ignoredAgain) {
// Process did not exit even after SIGKILL — record failure but continue
// cleaning up any remaining processes before propagating.
def failure = new RuntimeException("Instrumented process failed to exit after SIGKILL")
if (firstFailure == null) {
firstFailure = failure
} else {
firstFailure.addSuppressed(failure)
}
sleep 1_000
return // closure continue
}
}

if (exitValue != null) {
System.out.println("Instrumented process exited with " + exitValue)
} else if (tp != null) {
throw new TimeoutException("Instrumented process failed to exit")
}
System.err.println("Instrumented process exited with " + exitValue)
}

if (firstFailure != null) {
throw firstFailure
}
}

Expand Down