This is an automated email from the ASF dual-hosted git repository. clebertsuconic pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git
commit 50319192b3793ebfcf6980cc87fc294861f15898 Author: Clebert Suconic <[email protected]> AuthorDate: Mon May 5 10:52:29 2025 -0400 ARTEMIS-5463 ServerStatus.instance.server leaking between restarts --- .../core/server/impl/ActiveMQServerImpl.java | 7 ++++- .../artemis/core/server/impl/ServerStatus.java | 12 ++++++++- .../artemis/core/security/jaas/StatusTest.java | 8 +++--- ...ManagerLeakTest.java => StartStopLeakTest.java} | 31 +++++++++++++++------- 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java index 780c51e15e..ed5662c18e 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java @@ -516,7 +516,7 @@ public class ActiveMQServerImpl implements ActiveMQServer { this.serviceRegistry = serviceRegistry == null ? new ServiceRegistryImpl() : serviceRegistry; - this.serverStatus = ServerStatus.getInstanceFor(this); + this.serverStatus = ServerStatus.starting(this); } public class AddressSettingsMatchModifier implements HierarchicalObjectRepository.MatchModifier { @@ -1270,6 +1270,8 @@ public class ActiveMQServerImpl implements ActiveMQServer { } state = SERVER_STATE.STOPPING; + ServerStatus.stopping(this); + callPreDeActiveCallbacks(); if (criticalIOError) { @@ -3295,6 +3297,9 @@ public class ActiveMQServerImpl implements ActiveMQServer { if (state == SERVER_STATE.STOPPED) return false; + + ServerStatus.starting(this); + if (configuration.getJournalType() == JournalType.ASYNCIO) { if (!AIOSequentialFileFactory.isSupported()) { ActiveMQServerLogger.LOGGER.switchingNIO(); diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerStatus.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerStatus.java index 89c733c10e..e8470bd52f 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerStatus.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerStatus.java @@ -39,7 +39,13 @@ public class ServerStatus { instance.immutableStateValues.clear(); } - public static synchronized ServerStatus getInstanceFor(ActiveMQServerImpl activeMQServer) { + public static void stopping(ActiveMQServerImpl serverStopping) { + if (instance.server == serverStopping) { + clear(); + } + } + + public static synchronized ServerStatus starting(ActiveMQServerImpl activeMQServer) { if (instance.server == null) { instance.server = activeMQServer; instance.immutableStateValues.put("version", instance.server.getVersion().getFullVersion()); @@ -47,6 +53,10 @@ public class ServerStatus { return instance; } + public static ActiveMQServerImpl getServer() { + return instance.server; + } + public static synchronized ServerStatus getInstance() { return instance; } diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/security/jaas/StatusTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/security/jaas/StatusTest.java index a38fe2019e..ccaeaee489 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/security/jaas/StatusTest.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/security/jaas/StatusTest.java @@ -18,6 +18,7 @@ package org.apache.activemq.artemis.core.security.jaas; import static org.apache.activemq.artemis.core.server.impl.ServerStatus.JAAS_COMPONENT; import static org.apache.activemq.artemis.spi.core.security.jaas.PropertiesLoader.LOGIN_CONFIG_SYS_PROP_NAME; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import javax.security.auth.Subject; @@ -39,8 +40,9 @@ public class StatusTest extends ServerTestBase { private String existingPath = null; @BeforeEach - public void trackSystemProp() throws Exception { + public void prepareTest() throws Exception { existingPath = System.getProperty(LOGIN_CONFIG_SYS_PROP_NAME); + ServerStatus.clear(); } @AfterEach @@ -93,7 +95,7 @@ public class StatusTest extends ServerTestBase { final String BIRD = "later"; ActiveMQServerImpl server = new ActiveMQServerImpl(); - ServerStatus.getInstanceFor(server); + assertEquals(server, ServerStatus.getServer()); ServerStatus.getInstance().update(JAAS_COMPONENT + "/properties/" + EARLY_BIRD, "{\"reloadTime\":\"2\"}"); assertTrue(ServerStatus.getInstance().asJson().contains(EARLY_BIRD), "contains"); @@ -115,7 +117,7 @@ public class StatusTest extends ServerTestBase { ServerStatus.getInstance().update(JAAS_COMPONENT + "/properties/" + BIRD, "{\"reloadTime\":\"2\"}"); ActiveMQServerImpl server = new ActiveMQServerImpl(); - ServerStatus.getInstanceFor(server); + assertEquals(server, ServerStatus.getServer()); assertTrue(ServerStatus.getInstance().asJson().contains(EARLY_BIRD), "contains"); assertTrue(ServerStatus.getInstance().asJson().contains(BIRD), "contains"); diff --git a/tests/leak-tests/src/test/java/org/apache/activemq/artemis/tests/leak/AckManagerLeakTest.java b/tests/leak-tests/src/test/java/org/apache/activemq/artemis/tests/leak/StartStopLeakTest.java similarity index 73% rename from tests/leak-tests/src/test/java/org/apache/activemq/artemis/tests/leak/AckManagerLeakTest.java rename to tests/leak-tests/src/test/java/org/apache/activemq/artemis/tests/leak/StartStopLeakTest.java index a4ef097ca6..0b4b11cbc1 100644 --- a/tests/leak-tests/src/test/java/org/apache/activemq/artemis/tests/leak/AckManagerLeakTest.java +++ b/tests/leak-tests/src/test/java/org/apache/activemq/artemis/tests/leak/StartStopLeakTest.java @@ -26,19 +26,38 @@ import org.apache.activemq.artemis.tests.util.ActiveMQTestBase; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; -public class AckManagerLeakTest extends ActiveMQTestBase { + +/** Making sure the server will not leak after started / stopped */ +public class StartStopLeakTest extends ActiveMQTestBase { @Test public void testAckManagerLeak() throws Throwable { CheckLeak checkLeak = new CheckLeak(); + internalTest(checkLeak); + + clearServers(); + + MemoryAssertions.assertMemory(checkLeak, 0, ActiveMQServerImpl.class.getName()); + } + + // Creating a sub method to facilitate clearing references towards ActiveMQServerImpl + private CheckLeak internalTest(CheckLeak checkLeak) throws Exception { + assertNull(ServerStatus.getServer(), () -> "A previous test left a server hanging on ServerStatus -> " + ServerStatus.getServer()); ActiveMQServer server = createServer(false, true); for (int i = 0; i < 5; i++) { server.start(); MemoryAssertions.assertMemory(checkLeak, 1, AckManager.class.getName()); + + assertSame(server, ServerStatus.getServer()); + server.stop(false); - MemoryAssertions.assertMemory(checkLeak, 0, AckManager.class.getName()); + assertEquals(0, server.getExternalComponents().size()); + + assertNull(ServerStatus.getServer()); } MemoryAssertions.assertMemory(checkLeak, 1, PostOfficeImpl.class.getName()); @@ -46,12 +65,6 @@ public class AckManagerLeakTest extends ActiveMQTestBase { assertEquals(0, server.getExternalComponents().size()); MemoryAssertions.basicMemoryAsserts(); - server = null; - - clearServers(); - - ServerStatus.clear(); - - MemoryAssertions.assertMemory(checkLeak, 0, ActiveMQServerImpl.class.getName()); + return checkLeak; } } \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] For further information, visit: https://activemq.apache.org/contact
