Lock supplied exception when using Azure Service Bus with NServiceBus

I am having an issue with a long running Saga. It has to do a lot of processing but after sometime I get an error as follows
“The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue.”
I am extending the timeout during the processing to cater for the lenth of the processing

Can anyone point me in the right direction as how to ovecome this?

Have you looked at lock renewal configuration?

Thanks for your reply. Always appreciates
Yes I did but couldn’t get it to work. Possibly because i don’t really understand when the lock happens and what renewal actually does.
Should the renewal be set to the time of the transaction? Or does it get reset during the processing?
Can you recommend any further reading to better understand its workings?

The default setting for ASB transport is to set the lock duration on the queues to 5 minutes. Your lock renewal should be set to a value larger than that and no less than the maximum processing time. Processing in the saga raises a question, but that’s a different thread. You might want to take the processing out of the saga itself, as it means the saga is locked up for any other messages, including timeouts.
It might be worth going through your design with Particular folks. They can point out some point of improvement w/o exposing your IP/code on the public forum.

Thanks, much appreciated as always!
In this case the saga is a bulk extract of data from a 3rd party system which may take a day or more to run
To take the processing out of the saga, what would you recommend?
Is putting it in a command handler appropriate or is there a better approach?

That’s generally the recommendation, yes.

Thanks! Will try it now :slight_smile: