Fix CRIU subserver stop

This commit is contained in:
2026-09-03 02:24:49 +02:00
committed by fiercehut
parent 362468e756
commit 8401f67b24
@@ -138,14 +138,16 @@ public class Subserver {
writer.println(command);
}
public void sleep() {
try {
long pid = process.pid();
private ProcessHandle serverProcess() {
if (checkpoint) {
pid = process.children().findAny().map(ProcessHandle::pid).orElse(pid);
return process.children().findAny().orElseGet(process::toHandle);
}
return process.toHandle();
}
Runtime.getRuntime().exec(new String[]{"kill", "-SIGUSR1", Long.toString(pid)});
public void sleep() {
try {
Runtime.getRuntime().exec(new String[]{"kill", "-SIGUSR1", Long.toString(serverProcess().pid())});
} catch (IOException e) {
logger.log(Level.SEVERE, "Failed to send SIGUSR1 to subserver.", e);
}
@@ -162,7 +164,7 @@ public class Subserver {
public void stop() {
try {
process.destroy();
serverProcess().destroy();
if (!process.waitFor(1, TimeUnit.MINUTES)) {
forceStop();
} else if (thread.isAlive()) {
@@ -177,6 +179,7 @@ public class Subserver {
public void forceStop() {
try {
logger.log(Level.SEVERE, () -> serverName + " did not stop correctly, forcibly stopping!");
serverProcess().destroyForcibly();
process.destroyForcibly();
if (thread.isAlive()) thread.join();