0
votes

I have an Azure Function (Consumption Plan) triggered by a service bus queue.

I set maxAutoRenewDuration in host.json

{
  "version": "2.0",
  "extensions": {
    "serviceBus": {
      "messageHandlerOptions": {
        "maxAutoRenewDuration": "00:10:00"
      }
    }
  },
  "functionTimeout": "00:10:00"
}

The expectation is that message lock will be renewed up to 10 minutes. However, if I look at function execution logs, I see message lock expires every 5 minutes, effectively retriggering the function.

The execution logs:

enter image description here

As can be seen from the logs, function executes exactly after 5 minutes (when the lock expires). I'd expect to see function being re-triggered every 10 minutes (assuming ofc function execution is not done yet).

This is my function:

[FunctionName(nameof(MyFunc))]
public async Task MyFunc(
    [ServiceBusTrigger(queueName: "myqueue", Connection = "ServiceBusConnectionString")]
    Message message,
    ILogger logger,
    ExecutionContext executionContext)
{
    var invocationId = executionContext.InvocationId;

    // long running processing, that sometimes can stretch beyond 5 minutes
    await Process(invocationId, message);
}

How can I set auto renew duration, so that message lock being renewed until configured time ?

Azure Function v3, running .net core 3.1. OS: Windows

1
There's a documentation issue on this topic. Though the official document says maxAutoRenewDuration is (quoting) "The maximum duration within which the message lock will be renewed automatically." Which is aligned with what you see.Sean Feldman
Thank you @SeanFeldman! I've seen this issue, and the recommendation is You should make sure that maxAutoRenewDuration is as long as (or longer) than function timeout.. So for that reason I have functionTimeout equal to 10 minutes to match maxAutoRenewDuration. But as can be seen from the logs, message lock expires after 5 minutes, function doesn't time out which makes me think maxAutoRenewDuration setting is ignored.Michael

1 Answers

0
votes

It looks that in my case no need to set MaxAutoRenewDuration. Revisiting PeekLock behavior documentation

The Functions runtime receives a message in PeekLock mode. It calls Complete on the message if the function finishes successfully, or calls Abandon if the function fails. If the function runs longer than the PeekLock timeout, the lock is automatically renewed as long as the function is running.

I have functionTimeout configured in host.json, which is set to 10 minutes. So as long as function executes, message lock will be automatically renewed. I removed maxAutoRenewDuration from host.json and now function doesn't execute after message lock expiration.