I have a Web Application hosted in App Service which sends Message to my Azure ServiceBus Queue - this works fine. Then I have my azure function running under an App Service Plan (Dedicated Plan), which is a ServiceBusTrigger based, receives message from Azure ServiceBus Queue. The problem is that after about 10 minutes, when the first (previous) trigger process has not completed its work, Azure Function receives message from Servicebus queue again. My azure function executing logic can take up to 50-60 minutes.
Initially I was thinking the cause can be in Azure function either it is getting timeout or somewhere it is not behaving properly but while investigating 2 days with simulation of longer duration 20 minutes, 30 minutes we came to know that this is due to ServiceBus default behaviour.
ServiceBus have MaxAutoRenewDuration Property which is responsible for maximum duration within which the lock will be renewed automatically for a particular message in servicebus queue, however there is relation of it with MaxDeliveryCount.
The maximum MaxAutoRenewDuration for servicebus message is 5 minutes so if message is not processed by your azure function within 5 minutes(By default, the runtime calls Complete on the message if the function finishes successfully, or calls Abandon if the function fails.) it will increase the delivery count and re-try/re-queue the same process till delivery count reach to its limit. once delivery count limit reached, the servicebus queue message moved to DeadLetter Queue.
Not sure why message requeued in every 10 minutes if the maxautolock duration is just 5 minutes, what I noticed several times - it was always double the autorenewduration, if it is 5 minutes the function will retrigger or message get re-queued in 10 minutes, if it is 3 minutes, function will re-trigger in 6 minutes something that sort).
To resolve this requeue/re-triggers issue in every 10 minutes we need to update the AutoRenew duration. The maxAutoRenewDuration is configurable in Azure function host.json file , which maps to ServiceBusProcessor.MaxAutoLockRenewalDuration. The default value of this setting is 5 minutes.
https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus?tabs=isolated-process%2Cfunctionsv2%2Cextensionv2&pivots=programming-language-python#hostjson-settings
{
"version": "2.0",
"extensions": {
"serviceBus": {
"messageHandlerOptions": {
"autoComplete": true,
"maxConcurrentCalls": 16,
"maxAutoRenewDuration": "00:50:00"
}
}
},
"functionTimeout": "-1",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
},
"logLevel": {
"default": "Warning",
"Function": "Warning",
"Function.Accelerator.User": "Debug"
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
}
}
Thanks for reading, CloudOps ⌂Signing Off! 😊