[ 
https://issues.apache.org/jira/browse/AMQNET-610?focusedWorklogId=310300&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-310300
 ]

ASF GitHub Bot logged work on AMQNET-610:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 11/Sep/19 04:31
            Start Date: 11/Sep/19 04:31
    Worklog Time Spent: 10m 
      Work Description: Havret commented on issue #29: AMQNET-610: Race 
conditions during consumer creation
URL: https://github.com/apache/activemq-nms-amqp/pull/29#issuecomment-530123108
 
 
   Hi Chris,
   
   I see where it may come from:
   
   
https://github.com/apache/activemq-nms-amqp/blob/3c7ecd5c1b11d7211027293e4e4b38f05c21e0d9/src/NMS.AMQP/NmsMessageConsumer.cs#L399-L409
   
   In line 405 we are using AcknowledgementMode property of a session, and 
there is a check which throws exception when connection is closed. 
   
   In qpid jms they have this helper method ```isIndividualAcknowledge``` which 
circumvents the check that sits inside the getter. I remember asking myself 
during the implementation, why the heck they have this method when they can 
make the check directly. Apparently I've got my answer. 😂
   
   ```
   if (acknowledgementMode == Session.CLIENT_ACKNOWLEDGE) {
       envelope.getMessage().setAcknowledgeCallback(new 
JmsAcknowledgeCallback(session));
   } else if (session.isIndividualAcknowledge()) {
       envelope.getMessage().setAcknowledgeCallback(new 
JmsAcknowledgeCallback(session, envelope));
   }
   ```
   
   
https://github.com/apache/qpid-jms/blob/94822aced1380bae7935db6305250bf6bea7a9ac/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageConsumer.java#L497-L501
   
   @cjwmorgan-sol Could you be kind enough to file an issue, so it could be 
fixed in a separate PR? 
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 310300)
    Time Spent: 1h 10m  (was: 1h)

> Race condition during consumer creation
> ---------------------------------------
>
>                 Key: AMQNET-610
>                 URL: https://issues.apache.org/jira/browse/AMQNET-610
>             Project: ActiveMQ .Net
>          Issue Type: Bug
>          Components: AMQP, NMS
>            Reporter: Krzysztof Porebski
>            Priority: Critical
>          Time Spent: 1h 10m
>  Remaining Estimate: 0h
>
> Working on CI I found a race condition that reveals itself on slower machines 
> and may result in losing messages by consumers. 
> The race condition is a result of treating the creation of consumer resources 
> and starting them as an atomic operation:
> {code:java}
> public async Task Init()
> {
>     await Session.Connection.CreateResource(Info);
>     await Session.Connection.StartResource(Info);
> }
> {code}
> On slower boxes pending message may be delivered to the provider before above 
> code returns:
> {code:java}
> public IMessageConsumer CreateConsumer(IDestination destination, string 
> selector, bool noLocal)
> {
>     CheckClosed();    NmsMessageConsumer messageConsumer = new 
> NmsMessageConsumer(consumerIdGenerator.GenerateId(), this, destination, 
> selector, noLocal);
>     messageConsumer.Init().ConfigureAwait(false).GetAwaiter().GetResult();
> // here may be a race condition    
> consumers.TryAdd(messageConsumer.Info.Id, messageConsumer);
>     
>     return messageConsumer;
> }
> {code}
> If message arrives before `Init` returns (which means before newly created 
> consumer is added to the list of available consumers), the message will be 
> ignored. 
> {code:java}
> public void OnInboundMessage(InboundMessageDispatch envelope)
> {
>     if (consumers.TryGetValue(envelope.ConsumerInfo.Id, out 
> NmsMessageConsumer messageConsumer))
>     {
>         messageConsumer.OnInboundMessage(envelope);
>     }
> }
> {code}
>  
>  
>  



--
This message was sent by Atlassian Jira
(v8.3.2#803003)

Reply via email to