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

Send SIGTERM to parent process #1668

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,16 @@ public void close() throws IOException {
for (PidProcess pp : pidProcesses) {
pp.waitFor(gracefulShutdownTimeout.getSeconds(), TimeUnit.SECONDS);
}
if (pidProcesses.stream().anyMatch(pidProcess -> {
boolean isAnyProcessAlive = pidProcesses.stream().anyMatch(pidProcess -> {
try {
return pidProcess.isAlive();
} catch (IOException ignored) {
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return false;
})) {
});
if (isAnyProcessAlive) {
logger.atWarn()
.log("Command {} did not respond to interruption within timeout. Going to kill it now",
this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,13 @@ public UnixUserAttributes lookupCurrentUser() throws IOException {
public Set<Integer> killProcessAndChildren(Process process, boolean force, Set<Integer> additionalPids,
UserDecorator decorator)
throws IOException, InterruptedException {
PidProcess pp = Processes.newPidProcess(process);
PidProcess parentPidProcess = Processes.newPidProcess(process);

logger.atInfo().log("Killing child processes of pid {}, force is {}", pp.getPid(), force);
logger.atInfo().log("Killing child processes of pid {}, force is {}", parentPidProcess.getPid(), force);
Set<Integer> pids;
try {
pids = getChildPids(process);
logger.atDebug().log("Found children of {}. {}", pp.getPid(), pids);
logger.atDebug().log("Found children of {}. {}", parentPidProcess.getPid(), pids);
if (additionalPids != null) {
pids.addAll(additionalPids);
}
Expand All @@ -293,6 +293,9 @@ public Set<Integer> killProcessAndChildren(Process process, boolean force, Set<I

killProcess(force, decorator, pid);
}

logger.atInfo().log("Killing parent process {}, force is {}", parentPidProcess.getPid(), force);
killProcess(force, decorator, parentPidProcess.getPid());
} finally {
// calling process.destroy() here when force==false will cause the child process (component process) to be
// terminated immediately. This prevents the component process from shutting down gracefully.
Expand All @@ -301,11 +304,13 @@ public Set<Integer> killProcessAndChildren(Process process, boolean force, Set<I
if (process.isAlive()) {
// Kill parent process using privileged user since the parent process might be sudo which a
// non-privileged user can't kill
killProcess(true, getUserDecorator().withUser(getPrivilegedUser()), pp.getPid());
killProcess(true, getUserDecorator().withUser(getPrivilegedUser()), parentPidProcess.getPid());
}
}
}

// add parent pid so caller can validate if every process is properly terminated
pids.add(parentPidProcess.getPid());
return pids;
}

Expand Down