Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backports #1210

Merged
merged 4 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,12 @@ private Process startDaemonProcess(String daemonId, ClientOutput output) {
address = host + ":" + iPort;
output.accept(Message.buildStatus("Daemon listening for debugger on address: " + address));
args.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=" + address);
if (Environment.MVND_KEEP_ALIVE.getCommandLineOption(args) == null) {
System.setProperty(Environment.MVND_KEEP_ALIVE.getProperty(), "1h");
}
if (Environment.MVND_CONNECT_TIMEOUT.getCommandLineOption(args) == null) {
System.setProperty(Environment.MVND_CONNECT_TIMEOUT.getProperty(), "1h");
}
}
// jvm args
String jvmArgs = parameters.jvmArgs();
Expand Down
13 changes: 12 additions & 1 deletion common/src/main/java/org/mvndaemon/mvnd/common/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,18 @@ public enum Color {
auto;

public static Optional<Color> of(String color) {
return color == null ? Optional.empty() : Optional.of(Color.valueOf(color));
if (color == null) {
return Optional.empty();
} else if ("always".equals(color) || "yes".equals(color) || "force".equals(color)) {
return Optional.of(Color.always);
} else if ("never".equals(color) || "no".equals(color) || "none".equals(color)) {
return Optional.of(Color.never);
} else if ("auto".equals(color) || "tty".equals(color) || "if-tty".equals(color)) {
return Optional.of(Color.auto);
} else {
throw new IllegalArgumentException(
"Invalid color configuration value '" + color + "'. Supported are 'auto', 'always', 'never'.");
}
}
}

Expand Down
13 changes: 10 additions & 3 deletions common/src/main/java/org/mvndaemon/mvnd/common/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicLong;

public abstract class Message {
public static final int BUILD_REQUEST = 1;
Expand Down Expand Up @@ -125,10 +126,13 @@ public static Message read(DataInputStream input) throws IOException {
throw new IllegalStateException("Unexpected message type: " + type);
}

private static final AtomicLong sequence = new AtomicLong();

final long seq = sequence.incrementAndGet();
final long timestamp = System.nanoTime();

public static Comparator<Message> getMessageComparator() {
return Comparator.comparingInt(Message::getClassOrder).thenComparingLong(Message::timestamp);
return Comparator.comparingInt(Message::getClassOrder).thenComparingLong(Message::seq);
}

public static int getClassOrder(Message m) {
Expand Down Expand Up @@ -178,6 +182,10 @@ public static int getClassOrder(Message m) {
}
}

public long seq() {
return seq;
}

public long timestamp() {
return timestamp;
}
Expand Down Expand Up @@ -367,8 +375,7 @@ public String toString() {
return "BuildRequest{" + "args="
+ args + ", workingDir='"
+ workingDir + '\'' + ", projectDir='"
+ projectDir + '\'' + ", env='"
+ env + '\'' + '}';
+ projectDir + '\'' + '}';
}

@Override
Expand Down
11 changes: 9 additions & 2 deletions daemon/src/main/java/org/mvndaemon/mvnd/daemon/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,16 @@ private void client(SocketChannel socket) {
updateState(DaemonState.Idle);
return;
}
LOGGER.info("Request received: {}", message);
if (message instanceof BuildRequest) {
handle(connection, (BuildRequest) message);
BuildRequest buildRequest = (BuildRequest) message;
LOGGER.info("Request received: {}", message);
if (Boolean.getBoolean("mvnd.dump.client.env")) {
// Environment can contain passwords or tokens, so do not dump, unless specifically asked for
LOGGER.trace("Client environment dump: {}", buildRequest.getEnv());
}
handle(connection, buildRequest);
} else {
LOGGER.info("Ignoring message: {}", message);
}
} catch (Throwable t) {
LOGGER.error("Error reading request", t);
Expand Down
Loading