1

I'm using a Microsoft azure service bus queue and whenever I run it locally I get the following 2 errors:

Can't determine project language from files. Please use one of [--csharp, --javascript, --typescript, --java, --python, --powershell]

Microsoft.Azure.ServiceBus.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.

Here is my code:

public async Task Run([ServiceBusTrigger("<queue-name>", Connection = "queueConnectionString")] Message message, MessageReceiver messagereceiver, ILogger logger)
{
    var bodyJson = Encoding.UTF8.GetString(message.Body);
    var myMessage = JsonConvert.DeserializeObject<NewSubmissionMessage>(bodyJson);
    try
    {
        await _application.ProcessNewSubmission(myMessage);
        await messagereceiver.CompleteAsync(message.SystemProperties.LockToken);
    }
    catch (InvalidPackageException ex)
    {
        await messagereceiver.DeadLetterAsync(message.SystemProperties.LockToken, deadLetterReason: ex.Message);
    }
}
user989988
  • 3,006
  • 7
  • 44
  • 91

1 Answers1

2

Please check if you are using the latest version of the extension. If that is not 4.1.1 please upgrade it . ref: https://github.com/Azure/azure-functions-servicebus-extension/issues/38

In case such a issue occurs, the recommendation will be to use the service bus explorer tool to check the deadletter reason. The following document mentions details related to dead lettering in service bus and the various reasons for a message to get dead lettered: https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-dead-letter-queues

e.g. : if the issue is with the delivery count you may increase MaxDeliveryCount to its maximum value ( i.e. 10)

You may may try to implement the retry logic explicitly: https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-messaging-exceptions#messagelocklostexception https://github.com/jeffhollan/functions-csharp-queue-exponential/blob/master/ExponentialRetry.cs https://learn.microsoft.com/en-us/azure/architecture/best-practices/retry-service-specific#service-bus

Here are few relevant links which you can refer to :

The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue - due to AutoComplete defaulting to true. After updating the value to false it was resolved.

https://github.com/MassTransit/MassTransit/issues/802#issuecomment-294879874 – After switching to NetMessaging protocol from AMQP issue got resolved.

https://social.msdn.microsoft.com/Forums/azure/en-US/b86a64bb-cfcf-422b-a5fb-d831b7702c29/getting-an-exception-message-handler-encountered-an-exception?forum=servbus – After using “ReceiveandDelete” mode issue got resolved.

However, we recommend “PeekLock”.

For the first error, please refer to this