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 4527bc670 Let a session close quietly after the repository system shut
down (#2294)
4527bc670 is described below
commit 4527bc670e83d2af4a87c49fd15d7badfe73a2fd
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Mon Nov 16 20:40:48 2026 +0100
Let a session close quietly after the repository system shut down (#2294)
Shutting down runs the end handlers of every open session and reports each
as not closed. Closing such a session afterwards, as try-with-resources does
after an explicit shutdown, threw 'repository system is already shut down'
although nothing was left to do.
---
.../impl/DefaultRepositorySystemLifecycle.java | 7 +-
.../impl/DefaultRepositorySystemLifecycleTest.java | 78 ++++++++++++++++++++++
2 files changed, 84 insertions(+), 1 deletion(-)
diff --git
a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRepositorySystemLifecycle.java
b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRepositorySystemLifecycle.java
index 2472bbb19..85753c775 100644
---
a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRepositorySystemLifecycle.java
+++
b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRepositorySystemLifecycle.java
@@ -104,8 +104,13 @@ public class DefaultRepositorySystemLifecycle implements
RepositorySystemLifecyc
@Override
public void sessionEnded(CloseableSession session) {
requireNonNull(session, "session cannot be null");
- requireNotShutdown();
String sessionId = session.sessionId();
+ if (shutdown.get()) {
+ // systemEnded() already ran this session's handlers and reported
it as not closed; closing it now,
+ // for example from try-with-resources after an explicit shutdown,
has nothing left to do
+ onSessionEndedHandlers.remove(sessionId);
+ return;
+ }
ArrayList<Runnable> handlers = new ArrayList<>();
onSessionEndedHandlers.compute(sessionId, (k, v) -> {
if (v == null) {
diff --git
a/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultRepositorySystemLifecycleTest.java
b/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultRepositorySystemLifecycleTest.java
new file mode 100644
index 000000000..f3d569679
--- /dev/null
+++
b/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultRepositorySystemLifecycleTest.java
@@ -0,0 +1,78 @@
+/*
+ * 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.internal.impl;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.eclipse.aether.MultiRuntimeException;
+import org.eclipse.aether.RepositorySystemSession.CloseableSession;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class DefaultRepositorySystemLifecycleTest {
+
+ private static CloseableSession session(String id) {
+ CloseableSession session = mock(CloseableSession.class);
+ when(session.sessionId()).thenReturn(id);
+ return session;
+ }
+
+ @Test
+ void sessionEndedRunsItsHandlersOnce() {
+ DefaultRepositorySystemLifecycle lifecycle = new
DefaultRepositorySystemLifecycle();
+ CloseableSession session = session("s1");
+ AtomicInteger runs = new AtomicInteger();
+ lifecycle.sessionStarted(session);
+ lifecycle.addOnSessionEndedHandle(session, runs::incrementAndGet);
+
+ lifecycle.sessionEnded(session);
+ lifecycle.systemEnded();
+
+ assertEquals(1, runs.get());
+ }
+
+ @Test
+ void sessionClosedAfterShutdownDoesNotThrowOrRunItsHandlersAgain() {
+ DefaultRepositorySystemLifecycle lifecycle = new
DefaultRepositorySystemLifecycle();
+ CloseableSession session = session("s1");
+ AtomicInteger runs = new AtomicInteger();
+ lifecycle.sessionStarted(session);
+ lifecycle.addOnSessionEndedHandle(session, runs::incrementAndGet);
+
+ // shutting down with the session still open reports it, and runs its
handlers
+ assertThrows(MultiRuntimeException.class, lifecycle::systemEnded);
+ assertEquals(1, runs.get());
+
+ assertDoesNotThrow(() -> lifecycle.sessionEnded(session));
+ assertEquals(1, runs.get());
+ }
+
+ @Test
+ void sessionCannotStartAfterShutdown() {
+ DefaultRepositorySystemLifecycle lifecycle = new
DefaultRepositorySystemLifecycle();
+ lifecycle.systemEnded();
+
+ assertThrows(IllegalStateException.class, () ->
lifecycle.sessionStarted(session("s1")));
+ }
+}