question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MassTransit with Azure Functions error: "The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue."

See original GitHub issue

Hello!

I have an issue when using MassTransit with Azure Functions v1 (.NET Framework 4.6.1). I tried to run a basic Azure Function directly inspired from the sample provided in the project documentation : http://masstransit-project.com/MassTransit/usage/azure-functions.html.

The message is successfuly consumed by the IConsumer, and the Azure Function returns without any problem. However, I get the following error message immediately after the Azure Function execution ends : Microsoft.ServiceBus: The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue.

It looks like the Azure Functions SDK is expecting the message to still be present in the queue at the end of the function’s execution, in order to remove it. But the message is gone, the BrokeredMessageReceiver has already removed it from the queue by calling BrokeredMessage.CompleteAsync() in its Handle method.

Is there something I’m doing wrong?

Thanks!

SDK and lib versions:

  • Azure Functions v1 (.NET Framework 4.6.1)
  • Microsoft.NET.Sdk.Functions (1.0.4)
  • Newtonsoft.Json (11.0.2)
  • MassTransit.WebJobs.ServiceBus (5.1.4)

Sample log

Here is the log of the Azure Function’s execution. You can see that the function succeeds before the error occurs.

[17/08/2018 15:10:19] Host started (3431ms)
[17/08/2018 15:10:19] Job host started
[17/08/2018 15:10:31] Function started (Id=0f93ccf7-1018-4a70-9600-14e2aa2f7095)
[17/08/2018 15:10:31] Executing 'ProcessMessage' (Reason='New ServiceBus message detected on '<queue-name>'.', Id=0f93ccf7-1018-4a70-9600-14e2aa2f7095)
[17/08/2018 15:10:34] Consuming message 123456.
[17/08/2018 15:10:34] Function completed (Success, Id=0f93ccf7-1018-4a70-9600-14e2aa2f7095, Duration=2526ms)
[17/08/2018 15:10:34] Executed 'ProcessMessage' (Succeeded, Id=0f93ccf7-1018-4a70-9600-14e2aa2f7095)
[17/08/2018 15:10:35] A ScriptHost error has occurred
[17/08/2018 15:10:35] Microsoft.ServiceBus: The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue. TrackingId:555c414a-a5f7-47cb-9fdd-31e7eea9c753_G35_B0, SystemTracker:<servicebus-namespace>:Queue:<queue-name>, Timestamp:8/17/2018 3:10:36 PM.
[17/08/2018 15:10:35] MessageReceiver error (Action=Complete) : Microsoft.ServiceBus.Messaging.MessageLockLostException: The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue. TrackingId:555c414a-a5f7-47cb-9fdd-31e7eea9c753_G35_B0, SystemTracker:<servicebus-namespace>:Queue:<queue-name>, Timestamp:8/17/2018 3:10:36 PM ---> System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue. TrackingId:555c414a-a5f7-47cb-9fdd-31e7eea9c753_G35_B0, SystemTracker:<servicebus-namespace>:Queue:<queue-name>, Timestamp:8/17/2018 3:10:36 PM
[17/08/2018 15:10:35]    à Microsoft.ServiceBus.Messaging.Sbmp.DuplexRequestBindingElement.DuplexRequestSessionChannel.ThrowIfFaultMessage(Message wcfMessage)
[17/08/2018 15:10:35]    à Microsoft.ServiceBus.Messaging.Sbmp.DuplexRequestBindingElement.DuplexRequestSessionChannel.HandleMessageReceived(IAsyncResult result)
[17/08/2018 15:10:35] --- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée ---
[17/08/2018 15:10:35]    à Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
[17/08/2018 15:10:35]    à Microsoft.ServiceBus.Messaging.Sbmp.DuplexRequestBindingElement.DuplexRequestSessionChannel.EndRequest(IAsyncResult result)
[17/08/2018 15:10:35]    à Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement.ReconnectChannelFactory`1.RequestSessionChannel.RequestAsyncResult.<>c.<GetAsyncSteps>b__9_3(RequestAsyncResult thisPtr, IAsyncResult r)
[17/08/2018 15:10:35]    à Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result)
[17/08/2018 15:10:35] --- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée ---
[17/08/2018 15:10:35]    à Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
[17/08/2018 15:10:35]    à Microsoft.ServiceBus.Common.AsyncResult`1.End(IAsyncResult asyncResult)
[17/08/2018 15:10:35]    à Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement.ReconnectChannelFactory`1.RequestSessionChannel.EndRequest(IAsyncResult result)
[17/08/2018 15:10:35]    à Microsoft.ServiceBus.Messaging.Sbmp.RedirectBindingElement.RedirectContainerChannelFactory`1.RedirectContainerSessionChannel.RequestAsyncResult.<>c__DisplayClass8_1.<GetAsyncSteps>b__4(RequestAsyncResult thisPtr, IAsyncResult r)
[17/08/2018 15:10:35]    à Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result)
[17/08/2018 15:10:35] --- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée ---
[17/08/2018 15:10:35]    à Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
[17/08/2018 15:10:35]    à Microsoft.ServiceBus.Common.AsyncResult`1.End(IAsyncResult asyncResult)
[17/08/2018 15:10:35]    à Microsoft.ServiceBus.Messaging.Sbmp.RedirectBindingElement.RedirectContainerChannelFactory`1.RedirectContainerSessionChannel.EndRequest(IAsyncResult result)
[17/08/2018 15:10:35]    à Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement.ReconnectChannelFactory`1.RequestSessionChannel.RequestAsyncResult.<>c.<GetAsyncSteps>b__9_3(RequestAsyncResult thisPtr, IAsyncResult r)
[17/08/2018 15:10:35]    à Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result)
[17/08/2018 15:10:35] --- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée ---
[17/08/2018 15:10:35]    à Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
[17/08/2018 15:10:35]    à Microsoft.ServiceBus.Common.AsyncResult`1.End(IAsyncResult asyncResult)
[17/08/2018 15:10:35]    à Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement.ReconnectChannelFactory`1.RequestSessionChannel.EndRequest(IAsyncResult result)
[17/08/2018 15:10:35]    à Microsoft.ServiceBus.Messaging.Sbmp.SbmpTransactionalAsyncResult`1.<>c.<GetAsyncSteps>b__18_3(TIteratorAsyncResult thisPtr, IAsyncResult a)
[17/08/2018 15:10:35]    à Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result)
[17/08/2018 15:10:35] --- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée ---
[17/08/2018 15:10:35]    à Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
[17/08/2018 15:10:35]    à Microsoft.ServiceBus.Messaging.Sbmp.SbmpMessageReceiver.EndUpdateCommand(IAsyncResult result)[17/08/2018 15:10:35]    --- Fin de la trace de la pile d'exception interne ---
[17/08/2018 15:10:35]    à Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
[17/08/2018 15:10:35]    à Microsoft.ServiceBus.Common.AsyncResult`1.End(IAsyncResult asyncResult)
[17/08/2018 15:10:35]    à Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.<>c__22`1.<CallParallelAsync>b__22_1(TIteratorAsyncResult thisPtr, IAsyncResult r)
[17/08/2018 15:10:35]    à Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result)
[17/08/2018 15:10:35] Microsoft.ServiceBus: The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue. TrackingId:555c414a-a5f7-47cb-9fdd-31e7eea9c753_G35_B0, SystemTracker:<servicebus-namespace>:Queue:<queue-name>, Timestamp:8/17/2018 3:10:36 PM.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
phatboygcommented, Jan 3, 2019

This isn’t an issue now, and you need to select auto-confirm or whatever in your function config. Works only in the develop branch at this point until 5.2.1 is released.

0reactions
phatboygcommented, Nov 19, 2018

Once support is moved to Azure Functions v2, wonder if this will still be an issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - The lock supplied is invalid. Either the lock expired, or ...
I spent hours trying understand why I was getting a MessageLockLostException . The reason for me was due to AutoComplete defaulting to true....
Read more >
Getting MessageLockLostException while using ...
The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue - due to AutoComplete...
Read more >
Why am I getting “The lock supplied is invalid.” error when ...
Either the lock expired, or the message has already been removed from the queue" when deleting message from queue using below code. sbs....
Read more >
[Solved]-The lock supplied is invalid. Either the lock expired ...
Coding example for the question The lock supplied is invalid. Either the lock expired, or the message has already been removed from the...
Read more >
Azure Functions Transaction Mode Error - .NET 6.0
Messaging.ServiceBus: The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue, or was ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found