azure-functions-host icon indicating copy to clipboard operation
azure-functions-host copied to clipboard

Azure Functions return a 500 if request is too large (HTTP trigger)

Open bastbu opened this issue 1 year ago • 10 comments

Check for a solution in the Azure portal

Azure Functions have a configurable request size limit for HTTP triggers. The behavior of Kestrel, when a too large payload is encountered, is to return a 413, which indicates to the client that the issue is a too large request on the client side and cannot be retried.

Azure Functions have an internal behavior that masks this error, and returns a status code 500 instead, along with the following internal error messages, when I configure an Azure Function (tested with both Python and C#, as well as locally and in the cloud) with FUNCTIONS_REQUEST_BODY_SIZE_LIMIT=10:

Microsoft.Azure.WebJobs.Host: Exception binding parameter 'req'. Microsoft.AspNetCore.Server.Kestrel.Core: Request body too large. The max request body size is 10 bytes.

Investigative information

Please provide the following:

  • Timestamp: 10/9/2024, 1:30:44.082 PM
  • Function App version: 4.34.2.2
  • Function App name: -
  • Function name(s) (as appropriate): trigger
  • Invocation ID: 399cedc7-3aa2-4f08-8797-26689bcd9600
  • Region: West Europe

Repro steps

  1. Create a new HTTP-triggered function (either in C# or Python)
  2. Configure FUNCTIONS_REQUEST_BODY_SIZE_LIMIT to a low value, e.g. 10
  3. Execute a request against the HTTP endpoint with a payload larger than 10 bytes

Expected behavior

Azure Functions should return a 413 (and not print an error, as it's an expected condition).

Actual behavior

Azure Functions raise an internal exception and report a 500 to the client.

Known workarounds

I don't know of any workarounds for this.

Related information

  • Programming language used - Python/C#
  • Bindings used - HTTP

bastbu avatar Oct 10 '24 08:10 bastbu

Are you using streaming (python) or ASP.NET Core Integration (C#)? Or older HTTP models?

satvu avatar Nov 07 '24 19:11 satvu

I have similar issue. Running net8 isolated function. In Program.cs I have:

_ = services.Configure<KestrelServerOptions>(opt => opt.Limits.MaxRequestBodySize = 524_288_000);

When executed locally I have absolutely no problems running the code with files above 200MB. However, once this function is deployed to Azure (P1v3 plan) on Windows I can't process identical requests. I receive Response status code does not indicate success: 413 (Request Entity Too Large). From what I tested no files above 200MB are processed but I was not able to find any documentations or article that says there is hard limit set anywhere.

I've tried adding [DisableRequestSizeLimit] but nothing changes - same error.

So after all, is there hard limit for the body size or it can actually be unlimited, as per the documentation? If so, what I am doing wrong?

vindzhev avatar Nov 10 '24 21:11 vindzhev

Are you using streaming (python) or ASP.NET Core Integration (C#)? Or older HTTP models?

@satvu I'm not using streaming or the ASP.NET Core integration. I was using the latest scaffolding; hence I assume the latest HTTP models.

bastbu avatar Nov 15 '24 07:11 bastbu

Having the same issue and the recommended solutions of setting the MaxRequestBodySize seems not to be working, as nothing overrides the default value, does not matter what value it is changed to, but the docs says:

Gets or sets the maximum allowed size of any request body in bytes. When set to null, the maximum request body size is unlimited.

   services.Configure<KestrelServerOptions>(options =>
   {
       options.Limits.MaxRequestBodySize = null;
   });

Stefan94V avatar Nov 26 '24 14:11 Stefan94V

I have encountered the same issue: https://github.com/Azure/azure-functions-host/issues/10640

ipetrouchtchak-fi avatar Nov 26 '24 16:11 ipetrouchtchak-fi

any workaround or solution here?

toyip-fadv avatar Jan 27 '25 15:01 toyip-fadv

any news about this? it is a bit misleading for http client to receive an empty 500...

aagirre92 avatar Nov 28 '25 09:11 aagirre92

Does the workaround from #10640 work?

https://github.com/Azure/azure-functions-host/issues/10640#issuecomment-3412770686

satvu avatar Dec 01 '25 21:12 satvu

Does the workaround from #10640 work?

@satvu Not for me, as I am using Python (I used the C# variant only to validate that the issue occurs across languages).

bastbu avatar Dec 04 '25 07:12 bastbu

@bastbu Just to clarify - are you looking for an improved error message/status code, or do you need to be unblocked for Python scenarios as well?

satvu avatar Dec 16 '25 00:12 satvu