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 ae2d54f50 Stop the IPC client from reconnecting after the factory shut
down (#2299)
ae2d54f50 is described below
commit ae2d54f506d8c2476d7de128e2f4d9205c5c028c
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Mon Nov 16 20:41:12 2026 +0100
Stop the IPC client from reconnecting after the factory shut down (#2299)
close(Throwable) resets initialized so the client reconnects after an error;
after doShutdown() a still-held lock reconnected and could spawn a new
server.
---
.../org/eclipse/aether/named/ipc/IpcClient.java | 11 ++++++
.../eclipse/aether/named/ipc/IpcClientTest.java | 42 ++++++++++++++++++++++
2 files changed, 53 insertions(+)
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 5c31f8c95..9b4817087 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
@@ -81,6 +81,13 @@ public class IpcClient {
private static final SecureRandom SECURE_RANDOM = new SecureRandom();
protected volatile boolean initialized;
+
+ /**
+ * Set by {@link #close()}: the owning factory shut down, so no new
connection is made (and no new server is
+ * spawned) on behalf of a lock that is still held.
+ */
+ protected volatile boolean closed;
+
protected final Path lockPath;
protected final Path logPath;
protected final Path syncPath;
@@ -114,6 +121,9 @@ public class IpcClient {
if (!initialized) {
// caller must block on this method
synchronized (this) {
+ if (closed) {
+ throw new IOException("IPC client is closed");
+ }
if (!initialized) {
socket = createClient();
ByteChannel wrapper = new ByteChannelWrapper(socket);
@@ -384,6 +394,7 @@ public class IpcClient {
}
void close() {
+ closed = true;
try {
if (noFork) {
stopServer();
diff --git
a/maven-resolver-named-locks-ipc/src/test/java/org/eclipse/aether/named/ipc/IpcClientTest.java
b/maven-resolver-named-locks-ipc/src/test/java/org/eclipse/aether/named/ipc/IpcClientTest.java
new file mode 100644
index 000000000..16972266e
--- /dev/null
+++
b/maven-resolver-named-locks-ipc/src/test/java/org/eclipse/aether/named/ipc/IpcClientTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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 java.io.IOException;
+import java.nio.file.Path;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+class IpcClientTest {
+
+ /**
+ * A lock still held when the factory shuts down must not reconnect, and
so must not spawn a new server.
+ */
+ @Test
+ void closedClientDoesNotReconnect(@TempDir Path tempDir) {
+ IpcClient client = new IpcClient(tempDir.resolve("repository"),
tempDir.resolve("log"), null);
+ client.close();
+ assertThrows(IOException.class, client::ensureInitialized);
+ assertFalse(client.initialized);
+ }
+}