[ https://issues.apache.org/jira/browse/AMQNET-610?focusedWorklogId=309989&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-309989 ]
ASF GitHub Bot logged work on AMQNET-610: ----------------------------------------- Author: ASF GitHub Bot Created on: 10/Sep/19 17:39 Start Date: 10/Sep/19 17:39 Worklog Time Spent: 10m Work Description: cjwmorgan-sol commented on issue #29: AMQNET-610: Race conditions during consumer creation URL: https://github.com/apache/activemq-nms-amqp/pull/29#issuecomment-530044362 Seem pretty good to me however I did find one exception when trying to shutdown a connection with live traffic: PubSubLogger 9/10/2019 12:44:06 PM Error: Exception occurred: Apache.NMS.IllegalStateException: The Session is closed at Apache.NMS.AMQP.NmsSession.CheckClosed() at Apache.NMS.AMQP.NmsSession.get_AcknowledgementMode() at Apache.NMS.AMQP.NmsMessageConsumer.SetAcknowledgeCallback(InboundMessageDispatch envelope) at Apache.NMS.AMQP.NmsMessageConsumer.OnInboundMessage(InboundMessageDispatch envelope) at Apache.NMS.AMQP.NmsSession.OnInboundMessage(InboundMessageDispatch envelope) at Apache.NMS.AMQP.NmsConnection.OnInboundMessage(InboundMessageDispatch envelope) at Apache.NMS.AMQP.Provider.Failover.FailoverProvider.OnInboundMessage(InboundMessageDispatch envelope) at Apache.NMS.AMQP.Provider.Amqp.AmqpConsumer.OnMessage(IReceiverLink receiver, Message amqpMessage) at Amqp.ReceiverLink.OnTransfer(Delivery delivery, Transfer transfer, ByteBuffer buffer) at Amqp.Session.OnTransfer(Transfer transfer, ByteBuffer buffer) at Amqp.Connection.OnFrame(ByteBuffer buffer) I believe this can be fixed by using the Session.SessionInfo.AcknowledgementMode instead of Session.AcknowledgementMode in the Apache.NMS.AMQP.NmsMessageConsumer.SetAcknowledgeCallback method. I tried this and it worked. However, this seems somewhat odd to though as my application called stop on the connection before closing the connection. ---------------------------------------------------------------- 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: 309989) Time Spent: 0.5h (was: 20m) > 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: 0.5h > 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)