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-633: Fix session creation when connection not started
Date Thu, 16 Jan 2020 12:22:24 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 e2516e3  AMQNET-633: Fix session creation when connection not started
     new 8152249  Merge pull request #52 from HavretGC/AMQNET-633_Cannot-create-Session-when-Connection-not-started
e2516e3 is described below

commit e2516e3ba074a3bef4aec2796ec0a90574cd2d81
Author: Havret <h4vret@gmail.com>
AuthorDate: Fri Jan 3 13:17:23 2020 +0100

    AMQNET-633: Fix session creation when connection not started
---
 src/NMS.AMQP/NmsConnection.cs                      | 28 ++++++++++++----------
 .../Apache-NMS-AMQP-Interop-Test/NmsSessionTest.cs | 22 +++++++++++++++++
 2 files changed, 38 insertions(+), 12 deletions(-)

diff --git a/src/NMS.AMQP/NmsConnection.cs b/src/NMS.AMQP/NmsConnection.cs
index 6ce0903..0d637e5 100644
--- a/src/NMS.AMQP/NmsConnection.cs
+++ b/src/NMS.AMQP/NmsConnection.cs
@@ -416,24 +416,28 @@ namespace Apache.NMS.AMQP
 
             lock (syncRoot)
             {
-                if (!closed && connected.CompareAndSet(false, true))
+                if (closed || connected)
+                {
+                    return;
+                }
+                
+                try
+                {
+                    provider.Connect(ConnectionInfo).ConfigureAwait(false).GetAwaiter().GetResult();
+                    connected.Set(true);
+                }
+                catch (Exception e)
                 {
                     try
                     {
-                        provider.Connect(ConnectionInfo).ConfigureAwait(false).GetAwaiter().GetResult();
+                        provider.Close();
                     }
-                    catch (Exception e)
+                    catch
                     {
-                        try
-                        {
-                            provider.Close();
-                        }
-                        catch
-                        {
-                        }
-
-                        throw NMSExceptionSupport.Create(e);
+                        // ignored
                     }
+
+                    throw NMSExceptionSupport.Create(e);
                 }
             }
         }
diff --git a/test/Apache-NMS-AMQP-Interop-Test/NmsSessionTest.cs b/test/Apache-NMS-AMQP-Interop-Test/NmsSessionTest.cs
new file mode 100644
index 0000000..849f684
--- /dev/null
+++ b/test/Apache-NMS-AMQP-Interop-Test/NmsSessionTest.cs
@@ -0,0 +1,22 @@
+using System.Threading.Tasks;
+using Apache.NMS;
+using NUnit.Framework;
+
+namespace NMS.AMQP.Test
+{
+    public class NmsSessionTest : AmqpTestSupport
+    {
+        [Test, Timeout(10_000)]
+        public void TestCreateMultipleSessionsFromDifferentThreadsWhenConnectionNotStarted()
+        {
+            Connection = CreateAmqpConnection();
+            Assert.NotNull(Connection);
+
+            Parallel.For(0, 10, i =>
+            {
+                ISession session = Connection.CreateSession();
+                Assert.NotNull(session);
+            });
+        }
+    }
+}
\ No newline at end of file


Mime
View raw message