activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From michaelpea...@apache.org
Subject [activemq-nms-amqp] branch master updated: AMQNET-594: Race condition during session creation
Date Thu, 01 Aug 2019 15:43:40 GMT
This is an automated email from the ASF dual-hosted git repository.

michaelpearce pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-nms-amqp.git


The following commit(s) were added to refs/heads/master by this push:
     new 640ec72  AMQNET-594: Race condition during session creation
     new 8693c1b  Merge pull request #11 from HavretGC/AMQNET-594_Race_condition_during_session_creation
640ec72 is described below

commit 640ec72d4bfd9dd585dbec150ad608fab7b7549d
Author: Havret <h4vret@gmail.com>
AuthorDate: Thu Aug 1 13:05:41 2019 +0200

    AMQNET-594: Race condition during session creation
---
 src/NMS.AMQP/NmsConnection.cs | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/src/NMS.AMQP/NmsConnection.cs b/src/NMS.AMQP/NmsConnection.cs
index 0383c14..307ebed 100644
--- a/src/NMS.AMQP/NmsConnection.cs
+++ b/src/NMS.AMQP/NmsConnection.cs
@@ -446,23 +446,32 @@ namespace Apache.NMS.AMQP
 
         private void CreateNmsConnection()
         {
-            if (connected.CompareAndSet(false, true))
+            if (connected || closed)
             {
-                try
-                {
-                    provider.Connect(ConnectionInfo).ConfigureAwait(false).GetAwaiter().GetResult();
-                }
-                catch (Exception e)
+                return;
+            }
+
+            lock (syncRoot)
+            {
+                if (!closed && connected.CompareAndSet(false, true))
                 {
                     try
                     {
-                        provider.Close();
+                        provider.Connect(ConnectionInfo).ConfigureAwait(false).GetAwaiter().GetResult();
+                    
                     }
-                    catch
+                    catch (Exception e)
                     {
-                    }
+                        try
+                        {
+                            provider.Close();
+                        }
+                        catch
+                        {
+                        }
 
-                    throw NMSExceptionSupport.Create(e);
+                        throw NMSExceptionSupport.Create(e);
+                    }
                 }
             }
         }


Mime
View raw message