Skip to content

Commit

Permalink
[GR-59878] Exit CompilerDaemon when a SocketException is received.
Browse files Browse the repository at this point in the history
PullRequest: mx/1852
  • Loading branch information
dougxc committed Nov 27, 2024
2 parents e262358 + bd75044 commit a424108
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package com.oracle.mxtool.compilerserver;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
Expand Down Expand Up @@ -102,10 +103,14 @@ public Thread newThread(Runnable runnable) {
if (running) {
e.printStackTrace();
} else {
// Socket was closed
// we're shutting down
}
}
}
threadPool.shutdown();
while (!threadPool.isTerminated()) {
threadPool.awaitTermination(50, TimeUnit.MILLISECONDS);
}
}

private static void usage() {
Expand Down Expand Up @@ -152,14 +157,7 @@ public void run() {
String requestOrigin = connectionSocket.getInetAddress().getHostAddress();
String prefix = String.format("[%s:%s] ", Instant.now(), requestOrigin);
if (request == null || request.equals(REQUEST_HEADER_SHUTDOWN)) {
logf("%sShutting down%n", prefix);
running = false;
while (threadPool.getActiveCount() > 1) {
threadPool.awaitTermination(50, TimeUnit.MILLISECONDS);
}
serverSocket.close();
// Just to be sure...
System.exit(0);
shutdown(prefix);
} else if (request.startsWith(REQUEST_HEADER_COMPILE)) {
String commandLine = request.substring(REQUEST_HEADER_COMPILE.length());
String[] args = commandLine.split("\u0000");
Expand All @@ -177,8 +175,7 @@ public void run() {
int unrecognizedRequestCount = unrecognizedRequests.incrementAndGet();
System.err.printf("%sUnrecognized request %d (len=%d): \"%s\"%n", prefix, unrecognizedRequestCount, request.length(), printable(request));
if (unrecognizedRequestCount > MAX_UNRECOGNIZED_REQUESTS) {
System.err.printf("%sShutting down after receiving %d unrecognized requests%n", prefix, unrecognizedRequestCount);
System.exit(0);
shutdown(String.format("%sReceived %d unrecognized requests: ", prefix, unrecognizedRequestCount));
}
output.write("-1\n");
}
Expand All @@ -188,9 +185,22 @@ public void run() {
input.close();
connectionSocket.close();
}
} catch (SocketException se) {
// Lost connection to mx
shutdown("");
} catch (Exception ioe) {
ioe.printStackTrace();
}
}
}

private void shutdown(String prefix) {
logf("%sShutting down%n", prefix);
running = false;
try {
serverSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
2 changes: 1 addition & 1 deletion src/mx/_impl/mx.py
Original file line number Diff line number Diff line change
Expand Up @@ -18224,7 +18224,7 @@ def alarm_handler(signum, frame):
_CACHE_DIR = get_env('MX_CACHE_DIR', join(dot_mx_dir(), 'cache'))

# The version must be updated for every PR (checked in CI) and the comment should reflect the PR's issue
version = VersionSpec("7.35.1") # [GR-60117] Enable build support for JEP 493 enabled base JDKs
version = VersionSpec("7.35.2") # [GR-59878] Exit CompilerDaemon when a SocketException is received

_mx_start_datetime = datetime.utcnow()

Expand Down

0 comments on commit a424108

Please sign in to comment.