You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@activemq.apache.org by "Timothy Bish (JIRA)" <ji...@apache.org> on 2015/06/02 17:38:28 UTC

[jira] [Resolved] (AMQ-5599) Broker start thread hangs forever in async mode when startup of PersistenceAdapter is very fast

     [ https://issues.apache.org/jira/browse/AMQ-5599?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Timothy Bish resolved AMQ-5599.
-------------------------------
       Resolution: Fixed
    Fix Version/s: 5.12.0

> 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
>             Fix For: 5.12.0
>
>
> 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)