Return-Path: X-Original-To: apmail-activemq-commits-archive@www.apache.org Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 31850105EA for ; Wed, 11 Dec 2013 19:56:56 +0000 (UTC) Received: (qmail 55556 invoked by uid 500); 11 Dec 2013 19:56:56 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 55525 invoked by uid 500); 11 Dec 2013 19:56:56 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 55518 invoked by uid 99); 11 Dec 2013 19:56:56 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Dec 2013 19:56:56 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Dec 2013 19:56:55 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id F1D5F2388A02; Wed, 11 Dec 2013 19:56:34 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1550241 - /activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Tcp/TcpTransport.cs Date: Wed, 11 Dec 2013 19:56:34 -0000 To: commits@activemq.apache.org From: jgomes@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131211195634.F1D5F2388A02@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jgomes Date: Wed Dec 11 19:56:34 2013 New Revision: 1550241 URL: http://svn.apache.org/r1550241 Log: Move the blocking code outside of the lock section to avoid race condition when shutting down. Fixes [AMQNET-338]. (See https://issues.apache.org/jira/browse/AMQNET-338) Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Tcp/TcpTransport.cs Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Tcp/TcpTransport.cs URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Tcp/TcpTransport.cs?rev=1550241&r1=1550240&r2=1550241&view=diff ============================================================================== --- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Tcp/TcpTransport.cs (original) +++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Tcp/TcpTransport.cs Wed Dec 11 19:56:34 2013 @@ -188,6 +188,8 @@ namespace Apache.NMS.ActiveMQ.Transport. public void Close() { + Thread theReadThread = null; + lock(myLock) { if(closed.CompareAndSet(false, true)) @@ -238,20 +240,27 @@ namespace Apache.NMS.ActiveMQ.Transport. { } - if(null != readThread) + theReadThread = this.readThread; + this.readThread = null; + this.started = false; + } + } + + // Don't block on closing the read thread within the lock scope. + if(null != theReadThread) + { + try + { + if(Thread.CurrentThread != theReadThread && theReadThread.IsAlive) { - if(Thread.CurrentThread != readThread && readThread.IsAlive) + if(!theReadThread.Join((int) MAX_THREAD_WAIT.TotalMilliseconds)) { - if(!readThread.Join((int) MAX_THREAD_WAIT.TotalMilliseconds)) - { - readThread.Abort(); - } + theReadThread.Abort(); } - - readThread = null; } - - started = false; + } + catch + { } } }