activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ward V (JIRA)" <j...@apache.org>
Subject [jira] [Created] (AMQ-5599) Broker start thread hangs forever in async mode when startup of PersistenceAdapter is very fast
Date Thu, 19 Feb 2015 14:25:11 GMT
Ward V created AMQ-5599:
---------------------------

             Summary: Broker start thread hangs forever in async mode when startup of PersistenceAdapter
is very fast
                 Key: AMQ-5599
                 URL: https://issues.apache.org/jira/browse/AMQ-5599
             Project: ActiveMQ
          Issue Type: Bug
          Components: Broker
    Affects Versions: 5.10.0
            Reporter: Ward V


We encountered a situation where the startup of our broker fails sometimes. We investigated
this and have seen that this is caused by a race condition.
When the BrokerService is configured to be async, the starting of the broker will hang when
the starting of the PersistenceAdapter is faster than expected.

The ActiveMQ code will first start the persistence adapter, and then start the broker. When
startup is configured to be 'async', these actions will happen async (in separate threads).
Since these calls are async, we can not garuantee the order in which they will be finished.
Although the ActiveMQ code now relies on the fact that the starting of the persistence adapter
takes longer, and it waits in the starting of the broker for the starting of the persistence
adapter to finish. When the starting of the persistence adapter already finished before the
starting of the broker starts waiting for it, it will wait forever (and thus the broker cannot
get started).

In the following snippet from org.apache.activemq.broker.BrokerService this becomes clear:

'startPersistenceAdapter' is fast and already notifies: persistenceAdapterLock.notifyAll();.

'startBroker' will wait for notification but no one will ever notify it again: persistenceAdapterLock.wait();

---

startPersistenceAdapter(startAsync);
startBroker(startAsync);

private void startPersistenceAdapter(boolean async) throws Exception {
    if (async) {
        new Thread("Persistence Adapter Starting Thread") {
            @Override
            public void run() {
                try {
                    doStartPersistenceAdapter();
                } catch (Throwable e) {
                    startException = e;
                } finally {
                    synchronized (persistenceAdapterLock) {
                        persistenceAdapterLock.notifyAll();
                    }
                }
            }
        }.start();
    } else {
        doStartPersistenceAdapter();
    }
}

private void startBroker(boolean async) throws Exception {
    if (async) {
        new Thread("Broker Starting Thread") {
            @Override
            public void run() {
                try {
                    synchronized (persistenceAdapterLock) {
                        persistenceAdapterLock.wait();
                    }
                    doStartBroker();
                } catch (Throwable t) {
                    startException = t;
                }
            }
        }.start();
    } else {
        doStartBroker();
    }
}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message