APIM Error: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host

Mishra, Nitin 0 Reputation points
2024-11-15T12:05:53.0333333+00:00

We are getting the following error, Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host
Our Backend is hosted on AKS and is behind nginx. When we try to process a file which takes more than 5 minutes it throws out this error, we checked on nginx level and always got response. But when went through APIM it errors out and gives below error message.

We have increased the timeouts as well, also find the policy xml below.
User's image <policies>

<inbound>

<base/>

</inbound>

<backend>

<retry condition="@(context.Response.StatusCode == 0 || context.Response.StatusCode >= 500)" count="10" interval="10" max-interval="100" delta="10" first-fast-retry="false">

<forward-request timeout="1200" buffer-response="false" buffer-request-body="true"/>

</retry>

</backend>

<outbound>

<base/>

</outbound>

<on-error>

<base/>

</on-error>

</policies>

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,184 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. LeelaRajeshSayana-MSFT 16,281 Reputation points
    2024-11-15T16:29:17.6733333+00:00

    Hi @Mishra, Nitin Greetings! Welcome to Microsoft Q&A forum. Thank you for posting this question here.

    This is a limitation in Azure infrastructure. Even though, you set timeout="1200" in the forward-request policy, Values greater than 240 seconds may not be honored, because the underlying network infrastructure can drop idle connections after this time. Please refer the documentation on forward-request policy where the below limitation is mentioned.

    User's image

    You can make the backend service end point processing the file asynchronous and return a 202 response and implement some sort of polling mechanism on the backend service to get the status by hitting the end point in periodic intervals. Here is a typical flow to implement this

    Request and response flow for asynchronous HTTP requests

    Please also refer to this comment on the GitHub where a similar issue was discussed.


    If the response helped, please do click Accept Answer and Yes for the answer provided. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.

    0 comments No comments

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.