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


The following commit(s) were added to refs/heads/main by this push:
     new f1f017fb3b ARTEMIS-4279 Shutdown critical analyzer thread if error on 
broker initialization
f1f017fb3b is described below

commit f1f017fb3b2442a5789364aca7a9ec47a863a51b
Author: Stephen Higgs <[email protected]>
AuthorDate: Fri May 12 10:26:01 2023 -0400

    ARTEMIS-4279 Shutdown critical analyzer thread if error on broker 
initialization
    
    The broker process fails to exit if an error is encountered starting the 
NodeManager.  The issue is resolved by converting the critical analyzer thread 
to a daemon thread.  As added protection, the thread is manually stopped when 
this error is encountered.
---
 .../utils/critical/CriticalAnalyzerImpl.java       | 20 ++++++++++
 .../core/server/impl/ActiveMQServerImpl.java       |  8 +++-
 tests/smoke-tests/pom.xml                          | 28 +++++++++++++-
 .../artemis/tests/smoke/jdbc/JdbcStartupTest.java  | 43 ++++++++++++++++++++++
 4 files changed, 97 insertions(+), 2 deletions(-)

diff --git 
a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/critical/CriticalAnalyzerImpl.java
 
b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/critical/CriticalAnalyzerImpl.java
index 73df85a558..5fddd1d7d8 100644
--- 
a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/critical/CriticalAnalyzerImpl.java
+++ 
b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/critical/CriticalAnalyzerImpl.java
@@ -16,12 +16,15 @@
  */
 package org.apache.activemq.artemis.utils.critical;
 
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.ConcurrentModificationException;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.activemq.artemis.core.server.ActiveMQScheduledComponent;
+import org.apache.activemq.artemis.utils.ActiveMQThreadFactory;
 import org.apache.activemq.artemis.utils.collections.ConcurrentHashSet;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -48,11 +51,28 @@ public class CriticalAnalyzerImpl implements 
CriticalAnalyzer {
        *  issues and won't be able to shutdown the server or halt the VM
        */
       this.scheduledComponent = new ActiveMQScheduledComponent(null, null, 
checkTimeNanoSeconds, TimeUnit.NANOSECONDS, false) {
+
          @Override
          public void run() {
             logger.trace("Checking critical analyzer");
             check();
          }
+
+         @Override
+         protected ActiveMQThreadFactory getThreadFactory() {
+            return new ActiveMQThreadFactory("CriticalAnalyzer", 
"Critical-Analyzer-", true, getThisClassLoader());
+         }
+
+         private ClassLoader getThisClassLoader() {
+            return AccessController.doPrivileged(new 
PrivilegedAction<ClassLoader>() {
+               @Override
+               public ClassLoader run() {
+                  return CriticalAnalyzerImpl.this.getClass().getClassLoader();
+               }
+            });
+
+         }
+
       };
 
    }
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 20690cb835..b01a3ca759 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
@@ -689,7 +689,13 @@ public class ActiveMQServerImpl implements ActiveMQServer {
 
          nodeManager = 
createNodeManager(configuration.getNodeManagerLockLocation(), false);
 
-         nodeManager.start();
+         try {
+            nodeManager.start();
+         } catch (Exception e) {
+            //if there's an error here, ensure remaining threads shut down
+            stopTheServer(true);
+            throw e;
+         }
 
          ActiveMQServerLogger.LOGGER.serverStarting((haPolicy.isBackup() ? 
"backup" : "live"), configuration);
 
diff --git a/tests/smoke-tests/pom.xml b/tests/smoke-tests/pom.xml
index e7fd3e7db0..29607ee4d7 100644
--- a/tests/smoke-tests/pom.xml
+++ b/tests/smoke-tests/pom.xml
@@ -1281,7 +1281,33 @@
                      </args>
                   </configuration>
                </execution>
-
+               <execution>
+                  <phase>test-compile</phase>
+                  <id>create-jdbc-bad-driver</id>
+                  <goals>
+                     <goal>create</goal>
+                  </goals>
+                  <configuration>
+                     <role>amq</role>
+                     <user>admin</user>
+                     <password>admin</password>
+                     <allowAnonymous>false</allowAnonymous>
+                     <noWeb>true</noWeb>
+                     <instance>${basedir}/target/jdbc-bad-driver</instance>
+                     <args>
+                        <arg>--http-host</arg>
+                        <arg>${sts-http-host}</arg>
+                        <arg>--http-port</arg>
+                        <arg>8161</arg>
+                        <arg>--shared-store</arg>
+                        <arg>--jdbc</arg>
+                        <arg>--jdbc-connection-url</arg>
+                        <arg>tcp://noexist</arg>
+                        <arg>--jdbc-driver-class-name</arg>
+                        <arg>badDriver</arg>
+                     </args>
+                  </configuration>
+               </execution>
             </executions>
             <dependencies>
                <dependency>
diff --git 
a/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/jdbc/JdbcStartupTest.java
 
b/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/jdbc/JdbcStartupTest.java
new file mode 100644
index 0000000000..f77ee542a4
--- /dev/null
+++ 
b/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/jdbc/JdbcStartupTest.java
@@ -0,0 +1,43 @@
+/*
+ * 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.apache.activemq.artemis.tests.smoke.jdbc;
+
+import org.apache.activemq.artemis.tests.smoke.common.SmokeTestBase;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.concurrent.TimeUnit;
+
+public class JdbcStartupTest extends SmokeTestBase {
+
+   protected static final String SERVER_NAME = "jdbc-bad-driver";
+
+   @Test
+   public void startupBadJdbcConnectionTest() throws Exception {
+
+      Integer exitVal = -1;
+      Process p = startServer(SERVER_NAME, 0, 0);
+      try {
+         p.waitFor(10, TimeUnit.SECONDS);
+         exitVal = p.exitValue();
+      } catch (Exception e) {
+         Assert.fail();
+      }
+
+      Assert.assertEquals(0, (long) exitVal);
+   }
+}

Reply via email to