Skip to content

Commit

Permalink
improve diagnostics for unknown CompilerDaemon requests and be more l…
Browse files Browse the repository at this point in the history
…enient before shutting down

PullRequest: mx/1799
  • Loading branch information
dougxc committed May 22, 2024
2 parents c57f20f + 9713f94 commit 6869af0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.net.Socket;
import java.net.SocketException;
import java.time.Instant;
import java.util.Formatter;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
Expand All @@ -46,7 +47,7 @@ public abstract class CompilerDaemon {
/**
* The deamon will shut down after receiving this many requests with an unrecognized header.
*/
static final int MAX_UNRECOGNIZED_REQUESTS = 1000;
static final int MAX_UNRECOGNIZED_REQUESTS = 10_000;

protected void logf(String format, Object... args) {
if (verbose) {
Expand Down Expand Up @@ -128,6 +129,18 @@ public Connection(Socket connectionSocket, Compiler compiler) {
this.compiler = compiler;
}

private String printable(String s) {
Formatter buf = new Formatter();
s.chars().forEach(c -> {
if (c < 0x20 || c >= 0x7F) {
buf.format("\\u%04x", c);
} else {
buf.format("%c", c);
}
});
return buf.toString();
}

@Override
public void run() {
try {
Expand Down Expand Up @@ -161,8 +174,8 @@ public void run() {

output.write(result + "\n");
} else {
System.err.printf("%sUnrecognized request (len=%d): \"%s\"%n", prefix, request.length(), request);
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);
Expand Down
2 changes: 1 addition & 1 deletion src/mx/_impl/mx.py
Original file line number Diff line number Diff line change
Expand Up @@ -18173,7 +18173,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.25.6") # GR-54131 Fix codeowners incorrectly computing absolute file names for files from 'git diff'
version = VersionSpec("7.25.7") # GR-54207 - improve diagnostics for unknown CompilerDaemon requests

_mx_start_datetime = datetime.utcnow()

Expand Down

0 comments on commit 6869af0

Please sign in to comment.