activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mikael Finstad (Created) (JIRA)" <>
Subject [jira] [Created] (AMQNET-366) Deadlock when TCP connection breaks
Date Thu, 22 Dec 2011 14:47:30 GMT
Deadlock when TCP connection breaks

                 Key: AMQNET-366
             Project: ActiveMQ .Net
          Issue Type: Bug
          Components: ActiveMQ
    Affects Versions: 1.5.2
            Reporter: Mikael Finstad
            Assignee: Jim Gomes

When an ActiveMQ TCP connection gets broken (for instance when the ActiveMQ server goes down),
the AsyncCallExceptionListener is used by helper classes like SingleConnectionFactory and
SimpleMessageListenerContainer from to reconnect when connection becomes
available again.
>From this thread, these classes will call Close() on the connection which in turn calls
Shutdown on the ThreadPoolExecutor (from the final block in Connection.cs:Close()).
Inside Shutdown(), the execution hangs on this.executionComplete.WaitOne(), and there is a
deadlock because the AsyncCallExceptionListener call never returns, and nobody else triggers
the executionComplete event

Simple test case to reproduce the problem:

using System;
using System.Threading;
using Apache.NMS.ActiveMQ;
using NUnit.Framework;
using Spring.Messaging.Nms.Listener;

public class ActiveMQTests
    public void TestConnection()
        var connectionFactory = new ConnectionFactory("tcp://localhost:61616") {UserName =
"qwe", Password = "asd"};

        var messageListenerContainer = new SimpleMessageListenerContainer
            ConnectionFactory = connectionFactory,
            DestinationName = ""



Start debugging. Wait until it connects tothe ActiveMQ server, shutdown the ActiveMQ server,
pause execution and look at the Threads.

Example call stack:

[In a sleep, wait, or join]	 
[External Code]	 
Apache.NMS.ActiveMQ.DLL!Apache.NMS.ActiveMQ.Threads.ThreadPoolExecutor.Shutdown() Line 121
+ 0xe bytes	 
Apache.NMS.ActiveMQ.DLL!Apache.NMS.ActiveMQ.Connection.Close() Line 592 + 0xd bytes	 
connection, Apache.NMS.IConnectionFactory cf, bool started) Line 74 + 0x9 bytes	 
Line 432	 
Line 242	 
exception) Line 210	 
Apache.NMS.ActiveMQ.DLL!Apache.NMS.ActiveMQ.Connection.AsyncCallExceptionListener(object error)
Line 945 + 0x11 bytes	 
Apache.NMS.ActiveMQ.DLL!Apache.NMS.ActiveMQ.Threads.ThreadPoolExecutor.Future.Run() Line 63
+ 0x14 bytes	 
unused) Line 150 + 0xa bytes	 
[External Code]

Should it not be possible to Close the connection from the AsyncCallExceptionListener thread?

I've tried running executor.Shutdown() in Connection.Close (under finally block) in a new
thread and recompiling the NMS.ActiveMQ DLL, Like so:

if(executor != null)
	var thread = new Thread(delegate()

This seems to solve the problem, however I am not certain that this will not break anything

I am using Spring version 1.3.2 and apache.NMS version 1.5.0

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:!default.jspa
For more information on JIRA, see:


View raw message