Azure / azure-service-bus

☁️ Azure Service Bus service issue tracking and samples
https://azure.microsoft.com/services/service-bus
MIT License
585 stars 781 forks source link

MessageLockLostException randomly pop #418

Open Rayzbam opened 3 years ago

Rayzbam commented 3 years ago

Hi,

I'm using ServiceBus queue with maxConcurrentCalls enabled (setted to 100 actually) through AMQP connections. Sometimes, i'm just getting MessageLockLostException on some messages. I do know that this issue usually happened on Lock expiration but my process just take "normal" time, like 3sec and my lockExpiration is setted to 5minutes. I complete (or deadletter) my messages with the same MessageReceiver than the one which received the message to be processed (i know it's a prerequisite when using AMQP). I don't have a clue about this issue, i'm just getting started to think it's an issue, maybe with the maxConcurrentCalls idk.

My queue configuration :

LockDuration = TimeSpan.FromMinutes(5), MaxDeliveryCount = 1

        var options = new MessageHandlerOptions((e) => ExceptionReceivedHandler(key, e));
        options.AutoComplete = false;
        options.MaxAutoRenewDuration = TimeSpan.FromMinutes(10);
        options.MaxConcurrentCalls = maxConcurrentCalls; -- 100
        currentReceiver.RegisterMessageHandler(async (msg, token) => await HandleMessageBlockAsync(msg, token), options);`

Actual Behavior

  1. Received a message on a NON-partitionned queue without any PrefetchCount setted.
  2. Complete this message in a normal time for my application (5sec)
  3. Getting a MessageLockLostException "The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue, or was received by a different receiver instance."

Expected Behavior

  1. Received a message on a NON-partitionned queue without any PrefetchCount setted.
  2. Complete this message in a normal time for my application (5sec)
  3. Just delete the message from the queue and not sending it to my deadletters or increment my retryCount with an exception
EldertGrootenboer commented 2 years ago

This can occur if the connection between the service and the client is interrupted. We have an item in the backlog that should help prevent this type of behavior.

EldertGrootenboer commented 1 year ago

Thank you for your feedback on this item. We are currently actively working on this feature, however we don't have a timeline to share yet around its release.

EldertGrootenboer commented 6 months ago

We have brought this item in our current planning, and should be able to provide an update in the coming months.