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

havret pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-nms-openwire.git


The following commit(s) were added to refs/heads/main by this push:
     new c458814  AMQNET-727 Fix sync for pendingAck
c458814 is described below

commit c458814843d9a137ce9a315365f26cbe0ef5a2e6
Author: AndyDeMauriceGEDigital 
<[email protected]>
AuthorDate: Mon May 13 17:28:38 2024 -0400

    AMQNET-727 Fix sync for pendingAck
    
    * Fix sync for pendingAck
    
    * Add curly braces
---
 src/MessageConsumer.cs | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/src/MessageConsumer.cs b/src/MessageConsumer.cs
index 7120e6e..ab12836 100644
--- a/src/MessageConsumer.cs
+++ b/src/MessageConsumer.cs
@@ -662,12 +662,12 @@ namespace Apache.NMS.ActiveMQ
 
             if(this.deliveringAcks.CompareAndSet(false, true))
             {
-                if(this.IsAutoAcknowledgeEach)
+                using (this.deliveredMessagesLock.Lock())
                 {
-                    using(this.deliveredMessagesLock.Lock())
+                    if (this.IsAutoAcknowledgeEach)
                     {
                         ack = 
MakeAckForAllDeliveredMessages(AckType.ConsumedAck);
-                        if(ack != null)
+                        if (ack != null)
                         {
                             Tracer.DebugFormat("Consumer[{0}] DeliverAcks 
clearing the Dispatch list", ConsumerId);
                             this.deliveredMessages.Clear();
@@ -679,11 +679,11 @@ namespace Apache.NMS.ActiveMQ
                             this.pendingAck = null;
                         }
                     }
-                }
-                else if(pendingAck != null && pendingAck.AckType == (byte) 
AckType.ConsumedAck)
-                {
-                    ack = pendingAck;
-                    pendingAck = null;
+                    else if (pendingAck != null && pendingAck.AckType == 
(byte)AckType.ConsumedAck)
+                    {
+                        ack = pendingAck;
+                        pendingAck = null;
+                    }
                 }
 
                 if(ack != null)
@@ -1251,16 +1251,13 @@ namespace Apache.NMS.ActiveMQ
                 }
                 else if(IsClientAcknowledge || IsIndividualAcknowledge)
                 {
-                    bool messageAckedByConsumer = false;
 
                     using(await this.deliveredMessagesLock.LockAsync().Await())
                     {
-                        messageAckedByConsumer = 
this.deliveredMessages.Contains(dispatch);
-                    }
-
-                    if(messageAckedByConsumer)
-                    {
-                        await AckLaterAsync(dispatch, 
AckType.DeliveredAck).Await();
+                        if (this.deliveredMessages.Contains(dispatch))
+                        {
+                            await AckLaterAsync(dispatch, 
AckType.DeliveredAck).Await();
+                        }
                     }
                 }
                 else

Reply via email to