Azure Logic app APIM connector retry when Retry is set to None.

Banuka 70 Reputation points
2024-07-24T05:08:19.2333333+00:00

We have a logic app that uses APIM to call a backend API to create records using a POST request. We discovered some of the records that are created in backend is duplicated. when we looked deep into the issue we can see there is only one request from logic app to the APIM. To call APIM we use APIM connector and in the action Retry policy is set to None.

But, when we checked the Azure APIM logs we can see there are two requests around same time and one of them has been failed with Response code 0 "Client connection was unexpectedly closed". We Can't figure out what triggers the second request in APIM since the retry is set to None in logic app. And in the backend side logs we have both requests coming in.

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,168 questions
Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,201 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sina Salam 12,001 Reputation points
    2024-07-24T12:55:52.06+00:00

    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

    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


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.