You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2013/10/09 23:56:43 UTC

svn commit: r1530806 - in /activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.6.x: ./ src/main/csharp/Connection.cs src/main/csharp/Session.cs src/main/csharp/State/ConnectionStateTracker.cs

Author: tabish
Date: Wed Oct  9 21:56:42 2013
New Revision: 1530806

URL: http://svn.apache.org/r1530806
Log:
https://issues.apache.org/jira/browse/AMQNET-449

Race on connection interruption processing and consumer close.

Modified:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.6.x/   (props changed)
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.6.x/src/main/csharp/Connection.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.6.x/src/main/csharp/Session.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.6.x/src/main/csharp/State/ConnectionStateTracker.cs

Propchange: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.6.x/
------------------------------------------------------------------------------
  Merged /activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk:r1530805

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.6.x/src/main/csharp/Connection.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.6.x/src/main/csharp/Connection.cs?rev=1530806&r1=1530805&r2=1530806&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.6.x/src/main/csharp/Connection.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.6.x/src/main/csharp/Connection.cs Wed Oct  9 21:56:42 2013
@@ -90,7 +90,7 @@ namespace Apache.NMS.ActiveMQ
 		private ICompressionPolicy compressionPolicy = new CompressionPolicy();
 		private readonly IdGenerator clientIdGenerator;
 		private int consumerIdCounter = 0;
-		private volatile CountDownLatch transportInterruptionProcessingComplete;
+		private long transportInterruptionProcessingComplete;
 		private readonly MessageTransformation messageTransformation;
 		private readonly ThreadPoolExecutor executor = new ThreadPoolExecutor();
 		private AdvisoryConsumer advisoryConsumer = null;
@@ -1257,21 +1257,18 @@ namespace Apache.NMS.ActiveMQ
 
 			// Ensure that if there's an advisory consumer we don't add it to the
 			// set of consumers that need interruption processing.
-			this.transportInterruptionProcessingComplete =
-				new CountDownLatch(dispatchers.Count - (this.advisoryConsumer != null ? 1 : 0));
+			Interlocked.Exchange(ref transportInterruptionProcessingComplete, 1);
 
 			if(Tracer.IsDebugEnabled)
 			{
 				Tracer.DebugFormat("Connection[{0}]: Transport interrupted, dispatchers: {1}", this.ConnectionId, dispatchers.Count);
 			}
 
-			SignalInterruptionProcessingNeeded();
-
 			foreach(Session session in this.sessions)
 			{
 				try
 				{
-					session.ClearMessagesInProgress();
+					session.ClearMessagesInProgress(ref transportInterruptionProcessingComplete);
 				}
 				catch(Exception ex)
 				{
@@ -1280,6 +1277,14 @@ namespace Apache.NMS.ActiveMQ
 				}
 			}
 
+			if (Interlocked.Decrement(ref transportInterruptionProcessingComplete) > 0)
+			{
+				Tracer.DebugFormat("Transport interrupted - processing required, dispatchers: {0}",
+				                   Interlocked.Read(ref transportInterruptionProcessingComplete));
+
+				SignalInterruptionProcessingNeeded();
+			}
+
 			if(this.ConnectionInterruptedListener != null && !this.closing.Value)
 			{
 				try
@@ -1397,59 +1402,39 @@ namespace Apache.NMS.ActiveMQ
 
 		private void WaitForTransportInterruptionProcessingToComplete()
 		{
-			CountDownLatch cdl = this.transportInterruptionProcessingComplete;
-			if(cdl != null)
+			if(!closed.Value && !transportFailed.Value && Interlocked.Read(ref transportInterruptionProcessingComplete) > 0)
 			{
-				if(!closed.Value && cdl.Remaining > 0)
-				{
-					Tracer.WarnFormat("Connection[{0}]: Dispatch paused, waiting for outstanding dispatch interruption " +
-									  "processing ({1}) to complete..", this.ConnectionId, cdl.Remaining);
-					cdl.await(TimeSpan.FromSeconds(10));
-				}
-
+				Tracer.WarnFormat("Connection[{0}]: Dispatch with outstanding dispatch interruption processing count: {1}",
+				                  this.ConnectionId, Interlocked.Read(ref transportInterruptionProcessingComplete));
 				SignalInterruptionProcessingComplete();
 			}
 		}
 
 		internal void TransportInterruptionProcessingComplete()
 		{
-			CountDownLatch cdl = this.transportInterruptionProcessingComplete;
-			if(cdl != null)
+			if (Interlocked.Decrement(ref transportInterruptionProcessingComplete) == 0)
 			{
-				cdl.countDown();
-				try
-				{
-					SignalInterruptionProcessingComplete();
-				}
-				catch
-				{
-				}
+				SignalInterruptionProcessingComplete();
 			}
 		}
 
 		private void SignalInterruptionProcessingComplete()
 		{
-			CountDownLatch cdl = this.transportInterruptionProcessingComplete;
-			if(cdl.Remaining == 0)
+			Tracer.DebugFormat("Connection[{0}]: signalled TransportInterruptionProcessingComplete: {1}",
+			                   this.ConnectionId, Interlocked.Read(ref transportInterruptionProcessingComplete));
+
+			FailoverTransport failoverTransport = transport.Narrow(typeof(FailoverTransport)) as FailoverTransport;
+			if(failoverTransport != null)
 			{
+				failoverTransport.ConnectionInterruptProcessingComplete(this.info.ConnectionId);
 				if(Tracer.IsDebugEnabled)
 				{
-					Tracer.DebugFormat("Connection[{0}]: transportInterruptionProcessingComplete.", this.info.ConnectionId);
-				}
-
-				this.transportInterruptionProcessingComplete = null;
-
-				FailoverTransport failoverTransport = transport.Narrow(typeof(FailoverTransport)) as FailoverTransport;
-				if(failoverTransport != null)
-				{
-					failoverTransport.ConnectionInterruptProcessingComplete(this.info.ConnectionId);
-					if(Tracer.IsDebugEnabled)
-					{
-						Tracer.DebugFormat("Connection[{0}]: notified failover transport ({1})" +
-										   " of interruption completion.", this.ConnectionId, failoverTransport);
-					}
+					Tracer.DebugFormat("Connection[{0}]: notified failover transport ({1})" +
+									   " of interruption completion.", this.ConnectionId, failoverTransport);
 				}
 			}
+
+			Interlocked.Exchange(ref transportInterruptionProcessingComplete, 0);
 		}
 
 		private void SignalInterruptionProcessingNeeded()

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.6.x/src/main/csharp/Session.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.6.x/src/main/csharp/Session.cs?rev=1530806&r1=1530805&r2=1530806&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.6.x/src/main/csharp/Session.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.6.x/src/main/csharp/Session.cs Wed Oct  9 21:56:42 2013
@@ -922,7 +922,7 @@ namespace Apache.NMS.ActiveMQ
             }
         }
 
-        internal void ClearMessagesInProgress()
+        internal void ClearMessagesInProgress(ref long transportInterruptionProcessingComplete)
         {
             if(this.executor != null)
             {
@@ -940,6 +940,7 @@ namespace Apache.NMS.ActiveMQ
                 foreach(MessageConsumer consumer in this.consumers.Values)
                 {
                     consumer.InProgressClearRequired();
+					Interlocked.Increment(ref transportInterruptionProcessingComplete);
 					Scheduler.ExecuteAfterDelay(ClearMessages, consumer, 0);
                 }
             }

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.6.x/src/main/csharp/State/ConnectionStateTracker.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.6.x/src/main/csharp/State/ConnectionStateTracker.cs?rev=1530806&r1=1530805&r2=1530806&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.6.x/src/main/csharp/State/ConnectionStateTracker.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.6.x/src/main/csharp/State/ConnectionStateTracker.cs Wed Oct  9 21:56:42 2013
@@ -450,6 +450,8 @@ namespace Apache.NMS.ActiveMQ.State
                             {
                                 ss.RemoveConsumer(id);
                             }
+
+							cs.RecoveringPullConsumers.Remove(id);
                         }
                     }
                 }