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
+ {
}
}
}