Skip to content

Commit

Permalink
ARTEMIS-4279 Shutdown critical analyzer thread if error on broker ini…
Browse files Browse the repository at this point in the history
…tialization

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.
  • Loading branch information
sjhiggs authored and clebertsuconic committed May 16, 2023
1 parent 1d4139f commit f1f017f
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -48,11 +51,28 @@ public CriticalAnalyzerImpl() {
* 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();
}
});

}

};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,13 @@ private void internalStart() throws Exception {

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);

Expand Down
28 changes: 27 additions & 1 deletion tests/smoke-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit f1f017f

Please sign in to comment.