Ian1971
Ian1971

Reputation: 3706

Sproradic MessageLockLostException but lock not expired and is the same MessageReceiver instance

I've been scratching my head over this for a while. Most of the time it is working fine, but we get occasional clusters of MessageLockLostException. As far as I can tell the conditions are correct to be able to complete the message.

We are using Microsoft.Azure.ServiceBus.Core.MessageReceiver created as follows

var messageReceiver = new MessageReceiver(
                            this.ConnectionString,
                            EntityNameHelper.FormatSubscriptionPath(topicName, subName),
                            ReceiveMode.PeekLock);

Here is an example from our log

1/7/2020, 11:35:42.689 AM Got message for processing messageId:51c90000ff1c00035d9408d79365b47e, clientId=MessageReceiver20live/delivery-p/Subscriptions/1of1, LockToken:137a02f1-eed7-4b0e-a84b-996d9ede002a, Expiry:1/7/2020 11:40:42 AM, IsLockSet:True
DO STUFF
1/7/2020, 11:36:19.204 AM Complete Message "messageId":"51c90000ff1c00035d9408d79365b47e","clientId":"MessageReceiver20live/delivery-p/Subscriptions/1of1","lockToken":"137a02f1-eed7-4b0e-a84b-996d9ede002a"
1/7/2020, 11:36:19.291 AM Microsoft.Azure.ServiceBus.MessageLockLostException

The exception message is "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." But I don't think any of those conditions is true.

  1. You can seen above the lock token matches and is not expired.
  2. I know the message hasn't already been completed because it gets redelivered a few minutes later (coinciding with the lock expiry)
  3. The receiver instances match

Upvotes: 1

Views: 174

Answers (1)

Andrew
Andrew

Reputation: 131

Check that you are not exceeding your credit based throttling - see https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-throttling

I am getting lots of these false message lock exceptions even though I have plenty of time left until lock expiry, when trying tests of throughput that must be exceeding my limits. If I then issue a call to try and renew the lock straight after getting the lock exeption (as an expirement) I then receive a server busy exception like this one:

"The request was terminated because the namespace xxxxx is being throttled. Error code : 50009. Please wait 2 seconds and try again."

Upvotes: 1

Related Questions