Skip to content

Commit

Permalink
Improve build server shutdown procedure
Browse files Browse the repository at this point in the history
Use ServerCommand.STOP_SERVER as a first approach to make the build-
server shutdown. If that doesn't work send signal SIGTERM and if that
still doesn't work kill the server by sending SIGKILL.
  • Loading branch information
olpaw committed Apr 6, 2018
1 parent 00bc04e commit f73077a
Showing 1 changed file with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
package com.oracle.svm.driver;

import static com.oracle.svm.core.posix.headers.Signal.SignalEnum.SIGKILL;
import static com.oracle.svm.core.posix.headers.Signal.SignalEnum.SIGTERM;

import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -223,20 +224,35 @@ void abortTask() {
}

synchronized void shutdown() {
Signal.kill(pid, SIGTERM.getCValue());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
sendRequest(byteStreamToByteConsumer(baos), byteStreamToByteConsumer(baos), ServerCommand.STOP_SERVER);
showVerboseMessage(verboseServer, "Server stop response:" + new String(baos.toByteArray()));
long terminationTimeout = System.currentTimeMillis() + 20_000;
long killTimeout = terminationTimeout + 40_000;
long killedTimeout = killTimeout + 2_000;
showVerboseMessage(verboseServer, "Waiting for " + this + " to shutdown");
/* Release port only after server stops responding to it */
long timeout = System.currentTimeMillis() + 60_000;
showVerboseMessage(verboseServer, "Waiting for " + this + " to die");
while (isAlive()) {
boolean sentSIGTERM = false;
boolean sentSIGKILL = false;
do {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
throw showError("Woke up from waiting for " + this + " to die", e);
throw showError("Woke up from waiting for " + this + " to shutdown", e);
}
if (timeout < System.currentTimeMillis()) {
throw showError(this + " keeps responding to port " + port + " even after shutdown");
long now = System.currentTimeMillis();
if (!sentSIGTERM && terminationTimeout < now) {
showWarning(this + " keeps responding to port " + port + " even after sending STOP_SERVER");
Signal.kill(pid, SIGTERM.getCValue());
sentSIGTERM = true;
} else if (!sentSIGKILL && killTimeout < now) {
showWarning(this + " keeps responding to port " + port + " even after killing with SIGTERM");
Signal.kill(pid, SIGKILL.getCValue());
sentSIGKILL = true;
} else if (killedTimeout < now) {
throw showError(this + " keeps responding to port " + port + " even after killing with SIGKILL");
}
}
} while (isAlive());
deleteAllFiles(serverDir);
releasePortNumber(port);
}
Expand Down

0 comments on commit f73077a

Please sign in to comment.