Facing issue by changing azure function app version 3.x to 4.x


1.The existing function app runing with .netcore3.1, azure function version ~3.

2.The code was migrated from .netcore3.1 to .net 6.

3.In azure portal the function version was changed to version ~4 with existing function app.

4.Deployed migrated code in .net6 in the function app changed with function version ~4.

5.After doing the change of migration we are facing the issue. The associated eventgrid trigger is called multiple times and adding duplicate entries in our database.

Can you help to understand why this event grid trigger called multiple times?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,244 questions
Azure Event Grid
Azure Event Grid
An Azure event routing service designed for high availability, consistent performance, and dynamic scale.
312 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Grmacjon-MSFT 15,851 Reputation points

    @Bhanderi, Hareshkumar Babubhai HARBH we are sorry to hear that you're facing this issue with your Azure function app.

    The EventGrid trigger implementation has changed between version 3.x and 4.x of Azure Functions. In version 4.x, the EventGrid trigger now uses a different approach to handle events, which can lead to potential issues with duplicates. EventGrid offers at-least-once delivery guarantees, which means that events may be delivered multiple times in certain scenarios. This behavior is not related to the Azure Functions runtime version, but it can be exacerbated by changes in the trigger implementation.

    How did you migrate your app from version 3.x to version 4.x? your migrated .NET 6 code might not be using the built-in lease management in Azure Functions version 4.x. As a result, Event Grid might perceive delivery failures due to missing lease updates and keep retrying, leading to duplicate function invocations and database entries.

    Here are some possible solutions that fix this issue:

    • Instead of manual lease management, take advantage of the built-in lease functionality in Azure Functions version 4.x. It simplifies code and handles retries automatically. Refer to this Microsoft documentation for guidance on using Event Grid triggers with leases in version 4.x.
    • If you're still using a custom lease management solution, carefully review your code to ensure its compatible with Azure Functions version 4.x behavior. Make sure your code properly updates or releases leases after successful function execution to signal successful event processing to Event Grid.
    • In the Azure Functions 4.x runtime, you can enable function-level concurrency control to limit the number of concurrent executions of your function. This can help mitigate the issue of multiple instances processing the same event. To enable function-level concurrency control, go to the "Configuration" blade of your function app in the Azure portal, and add a new application setting with the key "FUNCTIONS_WORKER_PROCESS_COUNT" and the desired value (e.g., 1 to limit to a single instance).
    • Depending on your use case, you may want to consider using alternative EventGrid delivery options, such as the "Delivery with Retry" policy, which can help mitigate the issue of duplicate events.

    Hope that helps.


    0 comments No comments