Azure APIM-Client Connection Failure-Forward Request Timeout

Amit-J 316 Reputation points
2022-07-26T15:05:09.78+00:00

Hi,

My backend API is designed to download document and it works well from Postman even though the size of document in 500mb.
But when calling the same backend api via Azure APIM, it produces error (Message Payload too large to buffer or Client Connection Failure) for large documents.
Azure APIM is able to download 50-60mb documents successfully but fails for larger documents.

The request times out in 60-100 seconds which is lesser than the default 300 seconds.
As per MS docs, 240 seconds is the best timeout for APIM to work, still my requests are failing way before that.

I can see in logs that "backend response code" is 200 but the client connection is unexpectedly closed before the response document could be downloaded fully.
But the same client works perfectly well, when calling the backend api directly without apim.

Does it have something to do with buffer-response-size attribute ?

Please suggest the solution

Thanks,

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
1,916 questions
{count} votes

Accepted answer
  1. MuthuKumaranMurugaachari-MSFT 22,261 Reputation points
    2022-07-28T20:33:05.863+00:00

    @AmitJaiswal-8743 With your info above, it is pretty clear that it was failing when processing the response in the outbound policy.

    To answer your questions,

    You would like to know the memory limitations for Azure APIM specifically developer tier.

    • There is no limit (except consumption tier) as long as you do not buffer it at the APIM side (which means you can download very large files). But when you buffer or read entire response body through policy expressions like "System.Text.Encoding.UTF8.GetBytes(context.Request.Body.As<string>(preserveContent: true));", then there are limitations based on physical characteristics of VM (specific tier). But it's hard to have an exact number as it will depend on number of requests in flight at the same time and lot of other factors. I will pass the feedback to our product team to update the docs accordingly.

    For the second, unfortunately APIM wasn't built for such scenarios and this needs to be handled outside of APIM.

    You can also submit a feature request or feedback to our product team via aka.ms/apimwish. Feel free to add if you have any questions.


1 additional answer

Sort by: Most helpful
  1. Prashant Desai 76 Reputation points
    2022-07-26T23:40:18.94+00:00

    can you please try defining the forward-request advanced policy with the attribute buffer-response="false"
    The default value for this attribute is "true", which buffers the response in 8kb size chunks

    Please refer to this page: https://learn.microsoft.com/en-us/azure/api-management/api-management-advanced-policies#ForwardRequest

    <!-- operation level -->
    <policies>
    <inbound>
    <base/>
    </inbound>
    <backend>
    <forward-request timeout="300" buffer-response="false" />
    <!-- effective policy. note the absence of <base/> -->
    </backend>
    <outbound>
    <base/>
    </outbound>
    </policies>

    0 comments No comments