Hello Banuka,
Welcome to the Microsoft Q&A and thank you for posting your questions here.
Problem
I understand that you are having an issue where your Azure Logic App, which calls an API through Azure API Management (APIM), is unintentionally causing duplicate records to be created. Even though the retry policy in the Logic App is set to None, APIM logs show two requests being sent to the backend API, with one failing due to Client connection was unexpectedly closed.
Solution
This is a generic question due to no error code; I will provide some core area you will need to investigate for the best solution.
- The "Client connection was unexpectedly closed" error may indicate a network issue or timeout. If the Logic App didn't receive a response due to a connection issue, it might have triggered another request. Even without an explicit retry policy, network layers or proxies could cause this behavior.
- Check the timeout settings in APIM. If APIM's timeout is shorter than the backend API's response time, APIM might consider the request failed and issue another one. You can adjust the timeout settings to better align with your backend's response times.
- Ensure there are no hidden retries on the client-side (Logic App) or within any middleware or proxies between the Logic App and APIM. These retries could be happening outside of the Logic App's control.
- Review the APIM policy configuration for the API in question. Ensure that there are no policies (e.g., retry or circuit breaker policies) that might inadvertently cause a second request to be sent.
- Ensure that your backend API is idempotent, meaning it can handle multiple identical requests without causing unintended side effects, like creating duplicate records. This can be crucial in scenarios where requests might be accidentally duplicated.
- Implement thorough logging and monitoring on both the Logic App and the backend API. This can help you trace the path of requests and identify where and why duplicates might be occurring.
References
- Handle errors and exceptions in workflows - Azure Logic Apps
- Built-in operations versus Azure connectors in Standard - Azure Logic Apps
Accept Answer
I hope this is helpful! Do not hesitate to let me know if you have any other questions.
** Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful ** so that others in the community facing similar issues can easily find the solution.
Best Regards,
Sina Salam