Hi.
In Mule ESB,
I have detected a deadlock caused by the interaction between Spring and
ActiveMQ.
Basically, there are two execution chains that are causing the deadlock:

First Chain: when a Message arrives to the JMS Queue:

1) ActiveMQMessageConsumer.dispatch() gets the lock of
FifoMessageDispatchChannel.mutex.
2) ActiveMQMessageConsumer.dispatch() calls the onMessage() method without
releasing the lock.
3) onMessage Mule Implementation calls org.springframework.
SingleConnectionFactory$SharedConnectionInvocationHandler.invoke() because
It needs a toString of the used resource (in this case the connection) to
logging purposes.
3) in ToString() method,
org.springframework.SingleConnectionFactory.getConnection()
method is called and It takes the org.springframework.Single
ConnectionFactory.connectionMonitor lock to access to connection (that's a
shared resource).

Lock ordering in this chain:

FifoMessageDispatchChannel.mutex lock -> org.springframework.SingleC
onnectionFactory.connectionMonitor lock

Second Chain: when A reconnection-strategy is applied:

1) Mule stops the current connection calling org.springframework.Sin
gleConnectionFactory.localStop()
2) LocalStop takes the org.springframework.SingleConnectionFactory
.connectionMonitor lock.
3) After a chain of calls: FifoMessageDispatchChannel.stop() is called.
4) FifoMessageDispatchChannel.stop() takes the
FifoMessageDispatchChannel.mutex lock.

Lock Ordering in this case:

org.springframework.SingleConnectionFactory.connectionMonitor lock ->
FifoMessageDispatchChannel.mutex lock

As you can see, The chains don't take care about lock ordering, and It's
causing a deadlock.

I think the root problem is the invocation of the external implemented
method onEvent().
Calling the external implemented onEvent() method in the synchronized lock
can cause an unpredictable behaviour in lock ordering causing deadlock
issues.
I think It could be resolved if the lock is released before invoking
onEvent().
I would like to know their opinions about this case to report an issue if
It is necessary.

Thanks.
Cheers.

Reply via email to