You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by cs...@apache.org on 2025/07/02 13:04:45 UTC
(maven-resolver) branch master updated: Fixes for IPC (#1514)
This is an automated email from the ASF dual-hosted git repository.
cstamas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git
The following commit(s) were added to refs/heads/master by this push:
new f7f4f24e Fixes for IPC (#1514)
f7f4f24e is described below
commit f7f4f24ed3ec87b1d17cb235657e1711abb284bb
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Wed Jul 2 15:04:40 2025 +0200
Fixes for IPC (#1514)
There were some missing pieces in IPC client, mostly when using it in some test env (UT or IT) without forking. Also, a bug was present, that forked process expired while it had clients attached. Added IT proving it works now in these envs.
---
.../org/eclipse/aether/named/ipc/IpcClient.java | 31 ++++++++++-------
.../org/eclipse/aether/named/ipc/IpcServer.java | 6 ++--
.../aether/named/ipc/IpcAdapterNoForkIT.java | 39 ++++++++++++++++++++++
3 files changed, 61 insertions(+), 15 deletions(-)
diff --git a/maven-resolver-named-locks-ipc/src/main/java/org/eclipse/aether/named/ipc/IpcClient.java b/maven-resolver-named-locks-ipc/src/main/java/org/eclipse/aether/named/ipc/IpcClient.java
index ccb55958..a1af4f6d 100644
--- a/maven-resolver-named-locks-ipc/src/main/java/org/eclipse/aether/named/ipc/IpcClient.java
+++ b/maven-resolver-named-locks-ipc/src/main/java/org/eclipse/aether/named/ipc/IpcClient.java
@@ -75,25 +75,31 @@ public class IpcClient {
static final boolean IS_WINDOWS =
System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("win");
- volatile boolean initialized;
- Path lockPath;
- Path logPath;
- Path syncPath;
- SocketChannel socket;
- DataOutputStream output;
- DataInputStream input;
- Thread receiver;
- AtomicInteger requestId = new AtomicInteger();
- Map<Integer, CompletableFuture<List<String>>> responses = new ConcurrentHashMap<>();
+ protected volatile boolean initialized;
+ protected final Path lockPath;
+ protected final Path logPath;
+ protected final Path syncPath;
+ protected final boolean noFork;
+
+ protected SocketChannel socket;
+ protected DataOutputStream output;
+ protected DataInputStream input;
+ protected Thread receiver;
+
+ protected final AtomicInteger requestId = new AtomicInteger();
+ protected final Map<Integer, CompletableFuture<List<String>>> responses = new ConcurrentHashMap<>();
IpcClient(Path lockPath, Path logPath, Path syncPath) {
this.lockPath = lockPath;
this.logPath = logPath;
this.syncPath = syncPath;
+ this.noFork = Boolean.parseBoolean(
+ System.getProperty(IpcServer.SYSTEM_PROP_NO_FORK, Boolean.toString(IpcServer.DEFAULT_NO_FORK)));
}
void ensureInitialized() throws IOException {
if (!initialized) {
+ // caller must block on this method
synchronized (this) {
if (!initialized) {
socket = createClient();
@@ -152,8 +158,6 @@ public class IpcClient {
Path logFile = logPath.resolve("resolver-ipcsync-" + rand + ".log");
List<String> args = new ArrayList<>();
if (noNative) {
- boolean noFork = Boolean.parseBoolean(System.getProperty(
- IpcServer.SYSTEM_PROP_NO_FORK, Boolean.toString(IpcServer.DEFAULT_NO_FORK)));
if (noFork) {
IpcServer server = IpcServer.runServer(family, tmpaddr, rand);
close = server::close;
@@ -326,6 +330,9 @@ public class IpcClient {
}
void close() {
+ if (noFork) {
+ stopServer();
+ }
close(new IOException("Closing"));
}
diff --git a/maven-resolver-named-locks-ipc/src/main/java/org/eclipse/aether/named/ipc/IpcServer.java b/maven-resolver-named-locks-ipc/src/main/java/org/eclipse/aether/named/ipc/IpcServer.java
index 2b59342a..fbe12eef 100644
--- a/maven-resolver-named-locks-ipc/src/main/java/org/eclipse/aether/named/ipc/IpcServer.java
+++ b/maven-resolver-named-locks-ipc/src/main/java/org/eclipse/aether/named/ipc/IpcServer.java
@@ -64,7 +64,7 @@ public class IpcServer {
*/
public static final String SYSTEM_PROP_IDLE_TIMEOUT = "aether.named.ipc.idleTimeout";
- public static final int DEFAULT_IDLE_TIMEOUT = 60;
+ public static final int DEFAULT_IDLE_TIMEOUT = 300;
/**
* IPC socket family to use.
@@ -359,7 +359,7 @@ public class IpcServer {
c = clients.size();
}
if (!closing) {
- info("%d clients left", c);
+ info("%d clients remained", c);
}
}
}
@@ -372,7 +372,7 @@ public class IpcServer {
while (true) {
long current = System.nanoTime();
long left = (lastUsed + idleTimeout) - current;
- if (left < 0) {
+ if (clients.isEmpty() && left < 0) {
info("IpcServer expired, closing");
close();
break;
diff --git a/maven-resolver-named-locks-ipc/src/test/java/org/eclipse/aether/named/ipc/IpcAdapterNoForkIT.java b/maven-resolver-named-locks-ipc/src/test/java/org/eclipse/aether/named/ipc/IpcAdapterNoForkIT.java
new file mode 100644
index 00000000..bf07ce9b
--- /dev/null
+++ b/maven-resolver-named-locks-ipc/src/test/java/org/eclipse/aether/named/ipc/IpcAdapterNoForkIT.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eclipse.aether.named.ipc;
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+
+public class IpcAdapterNoForkIT extends NamedLockFactoryAdapterTestSupport {
+ @BeforeAll
+ static void createNamedLockFactory() {
+ // the goal if this IT to prove it works when noFork=true and IpcClient will clean up server
+ // needed in cases like in Maven, when there is no direct access to IpcNamedLockFactory
+ // to override doShutdown method like in IpcAdapterIT
+ System.setProperty(IpcServer.SYSTEM_PROP_NO_FORK, Boolean.TRUE.toString());
+ System.setProperty(IpcServer.SYSTEM_PROP_DEBUG, Boolean.TRUE.toString());
+ setNamedLockFactory(new IpcNamedLockFactory());
+ }
+
+ @AfterAll
+ static void cleanup() {
+ System.clearProperty(IpcServer.SYSTEM_PROP_NO_FORK);
+ }
+}