You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ha...@apache.org on 2026/05/17 19:36:30 UTC

(activemq-nms-amqp) branch Add-test-for-AsyncListener-behavior-after-removal-to-prevent-deadlock created (now 7dc40eb)

This is an automated email from the ASF dual-hosted git repository.

Havret pushed a change to branch Add-test-for-AsyncListener-behavior-after-removal-to-prevent-deadlock
in repository https://gitbox.apache.org/repos/asf/activemq-nms-amqp.git


      at 7dc40eb  Add test for AsyncListener behavior after removal to prevent deadlock

This branch includes the following new commits:

     new 7dc40eb  Add test for AsyncListener behavior after removal to prevent deadlock

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@activemq.apache.org
For additional commands, e-mail: commits-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact



(activemq-nms-amqp) 01/01: Add test for AsyncListener behavior after removal to prevent deadlock

Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

Havret pushed a commit to branch Add-test-for-AsyncListener-behavior-after-removal-to-prevent-deadlock
in repository https://gitbox.apache.org/repos/asf/activemq-nms-amqp.git

commit 7dc40ebc6fac2e161ba19d17d495dc43024e068a
Author: Havret <h4...@gmail.com>
AuthorDate: Sun May 17 21:35:02 2026 +0200

    Add test for AsyncListener behavior after removal to prevent deadlock
---
 .../Async/ConsumerIntegrationTestAsync.cs          | 45 ++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/test/Apache-NMS-AMQP-Test/Integration/Async/ConsumerIntegrationTestAsync.cs b/test/Apache-NMS-AMQP-Test/Integration/Async/ConsumerIntegrationTestAsync.cs
index 4ef6078..916af5a 100644
--- a/test/Apache-NMS-AMQP-Test/Integration/Async/ConsumerIntegrationTestAsync.cs
+++ b/test/Apache-NMS-AMQP-Test/Integration/Async/ConsumerIntegrationTestAsync.cs
@@ -1094,5 +1094,50 @@ namespace NMS.AMQP.Test.Integration.Async
                 testPeer.WaitForAllMatchersToComplete(2000);
             }
         }
+
+        [Test, Timeout(20_000)]
+        public async Task TestAsyncListenerAddAfterRemoveReceivesMessages()
+        {
+            using (TestAmqpPeer testPeer = new TestAmqpPeer())
+            {
+                IConnection connection = await EstablishConnectionAsync(testPeer);
+                await connection.StartAsync();
+
+                testPeer.ExpectBegin();
+                ISession session = await connection.CreateSessionAsync(AcknowledgementMode.AutoAcknowledge);
+                IQueue destination = await session.GetQueueAsync("myQueue");
+
+                testPeer.ExpectReceiverAttach();
+                testPeer.ExpectLinkFlowRespondWithTransfer(message: CreateMessageWithContent(), count: 1);
+                testPeer.ExpectDispositionThatIsAcceptedAndSettled();
+
+                IMessageConsumer consumer = await session.CreateConsumerAsync(destination);
+
+                // Remove a handler that was never added — this is the sequence that triggered the bug.
+                // With the buggy LockAsync() call, the semaphore was acquired but never released,
+                // causing the subsequent add to deadlock.
+                AsyncMessageListener handler = (_, _) => Task.CompletedTask;
+                consumer.AsyncListener -= handler;
+
+                ManualResetEvent messageReceived = new ManualResetEvent(false);
+                consumer.AsyncListener += async (message, ct) =>
+                {
+                    await Task.CompletedTask;
+                    messageReceived.Set();
+                };
+
+                Assert.True(messageReceived.WaitOne(4000), "Message was not received after adding AsyncListener following a remove.");
+
+                testPeer.WaitForAllMatchersToComplete(2000);
+
+                testPeer.ExpectDetach(expectClosed: true, sendResponse: true, replyClosed: true);
+                await consumer.CloseAsync();
+
+                testPeer.ExpectClose();
+                await connection.CloseAsync();
+
+                testPeer.WaitForAllMatchersToComplete(2000);
+            }
+        }
     }
 }
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@activemq.apache.org
For additional commands, e-mail: commits-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact