Skip to content

Commit a424108

Browse files
committed
[GR-59878] Exit CompilerDaemon when a SocketException is received.
PullRequest: mx/1852
2 parents e262358 + bd75044 commit a424108

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

java/com.oracle.mxtool.compilerserver/src/com/oracle/mxtool/compilerserver/CompilerDaemon.java

+21-11
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package com.oracle.mxtool.compilerserver;
2626

2727
import java.io.BufferedReader;
28+
import java.io.IOException;
2829
import java.io.InputStreamReader;
2930
import java.io.OutputStreamWriter;
3031
import java.net.ServerSocket;
@@ -102,10 +103,14 @@ public Thread newThread(Runnable runnable) {
102103
if (running) {
103104
e.printStackTrace();
104105
} else {
105-
// Socket was closed
106+
// we're shutting down
106107
}
107108
}
108109
}
110+
threadPool.shutdown();
111+
while (!threadPool.isTerminated()) {
112+
threadPool.awaitTermination(50, TimeUnit.MILLISECONDS);
113+
}
109114
}
110115

111116
private static void usage() {
@@ -152,14 +157,7 @@ public void run() {
152157
String requestOrigin = connectionSocket.getInetAddress().getHostAddress();
153158
String prefix = String.format("[%s:%s] ", Instant.now(), requestOrigin);
154159
if (request == null || request.equals(REQUEST_HEADER_SHUTDOWN)) {
155-
logf("%sShutting down%n", prefix);
156-
running = false;
157-
while (threadPool.getActiveCount() > 1) {
158-
threadPool.awaitTermination(50, TimeUnit.MILLISECONDS);
159-
}
160-
serverSocket.close();
161-
// Just to be sure...
162-
System.exit(0);
160+
shutdown(prefix);
163161
} else if (request.startsWith(REQUEST_HEADER_COMPILE)) {
164162
String commandLine = request.substring(REQUEST_HEADER_COMPILE.length());
165163
String[] args = commandLine.split("\u0000");
@@ -177,8 +175,7 @@ public void run() {
177175
int unrecognizedRequestCount = unrecognizedRequests.incrementAndGet();
178176
System.err.printf("%sUnrecognized request %d (len=%d): \"%s\"%n", prefix, unrecognizedRequestCount, request.length(), printable(request));
179177
if (unrecognizedRequestCount > MAX_UNRECOGNIZED_REQUESTS) {
180-
System.err.printf("%sShutting down after receiving %d unrecognized requests%n", prefix, unrecognizedRequestCount);
181-
System.exit(0);
178+
shutdown(String.format("%sReceived %d unrecognized requests: ", prefix, unrecognizedRequestCount));
182179
}
183180
output.write("-1\n");
184181
}
@@ -188,9 +185,22 @@ public void run() {
188185
input.close();
189186
connectionSocket.close();
190187
}
188+
} catch (SocketException se) {
189+
// Lost connection to mx
190+
shutdown("");
191191
} catch (Exception ioe) {
192192
ioe.printStackTrace();
193193
}
194194
}
195195
}
196+
197+
private void shutdown(String prefix) {
198+
logf("%sShutting down%n", prefix);
199+
running = false;
200+
try {
201+
serverSocket.close();
202+
} catch (IOException e) {
203+
e.printStackTrace();
204+
}
205+
}
196206
}

src/mx/_impl/mx.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18224,7 +18224,7 @@ def alarm_handler(signum, frame):
1822418224
_CACHE_DIR = get_env('MX_CACHE_DIR', join(dot_mx_dir(), 'cache'))
1822518225

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

1822918229
_mx_start_datetime = datetime.utcnow()
1823018230

0 commit comments

Comments
 (0)