james created AMQ-5118:
--------------------------

             Summary: Race condition with embedded broker asynchronous startup
                 Key: AMQ-5118
                 URL: https://issues.apache.org/jira/browse/AMQ-5118
             Project: ActiveMQ
          Issue Type: Bug
          Components: Broker
    Affects Versions: 5.9.0
            Reporter: james


We run activemq as an embedded broker using the asynchronous startup option.  
We after the start async call returns, we create a vm connector with the extra 
options "?create=false&waitForStart=60000".  There is a timing hole where the 
BrokerService has been registered with the BrokerRegistry (and is found by the 
connection factory), but the BrokerServer.broker member variable has not yet 
been assigned (in fact, there may be some memory visibility issues here).  The 
VMTransportFactory eventually generates a call to BrokerService.getBroker(), 
which (since broker == null) attempts to create a broker instance.  This 
ultimately results in a JMX exception due to multiple instances being 
registered (assuming you have jmx enabled).

{noformat}
javax.jms.JMSException: Could not create Transport. Reason: 
java.io.IOException: Status MBean could not be registe
red in JMX: org.apache.activemq:type=Broker,brokerName=internal,service=Health
  at 
org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:36)
  at 
org.apache.activemq.ActiveMQConnectionFactory.createTransport(ActiveMQConnectionFactory.java:260)
  at 
org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:273)
  at 
org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:246)
  at 
org.apache.activemq.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:186)
  at <internal stacktrace ommitted>
  at 
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
  at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
  at java.lang.Thread.run(Thread.java:662)
Caused by: java.io.IOException: Status MBean could not be registered in JMX: 
org.apache.activemq:type=Broker,brokerName=internal,service=Health
  at 
org.apache.activemq.util.IOExceptionSupport.create(IOExceptionSupport.java:27)
  at 
org.apache.activemq.broker.BrokerService.addInterceptors(BrokerService.java:2242)
  at 
org.apache.activemq.broker.BrokerService.createBroker(BrokerService.java:2123)
  at org.apache.activemq.broker.BrokerService.getBroker(BrokerService.java:906)
  at 
org.apache.activemq.broker.TransportConnector.start(TransportConnector.java:201)
  at 
org.apache.activemq.transport.vm.VMTransportFactory.doCompositeConnect(VMTransportFactory.java:140)
  at 
org.apache.activemq.transport.vm.VMTransportFactory.doConnect(VMTransportFactory.java:54)
  at 
org.apache.activemq.transport.TransportFactory.connect(TransportFactory.java:64)
  at 
org.apache.activemq.ActiveMQConnectionFactory.createTransport(ActiveMQConnectionFactory.java:258)
  ... 37 more
Caused by: javax.management.InstanceAlreadyExistsException: 
org.apache.activemq:type=Broker,brokerName=internal,service=Health
  at com.sun.jmx.mbeanserver.Repository.addMBean(Repository.java:453)
  at 
com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.internal_addObject(DefaultMBeanServerInterceptor.java:1484)
  at 
com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(DefaultMBeanServerInterceptor.java:963)
  at 
com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:917)
  at 
com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:312)
  at 
com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:483)
  at 
org.apache.activemq.broker.jmx.ManagementContext.registerMBean(ManagementContext.java:380)
  at 
org.apache.activemq.broker.jmx.AnnotatedMBean.registerMBean(AnnotatedMBean.java:72)
  at 
org.apache.activemq.broker.BrokerService.addInterceptors(BrokerService.java:2240)
  ... 44 more
{noformat}



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to