-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Description
Is there an existing issue for this?
- I have searched the existing issuesTo pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
Describe the bug
When uploading a file larger than a default limit (30000000 bytes) Kestrel returns 400 status code, instead of 413.
Seems like similar issue have been already proposed #47525
Expected Behavior
I expect 413 status code in this case.
Http1ContentLengthMessageBody.OnReadStarting
throws new BadHttpRequestException(CoreStrings.FormatBadRequest_RequestBodyTooLarge(detail), StatusCodes.Status413PayloadTooLarge, reason);
when body size is greater setting 413 status code.
Then HttpProtocol.ProcessRequestsAsync
catches this exception calling HttpProtocol.SetBadRequestState
. And at this moment HttpProtocol.HasResponseStarted == true
what prevents setting status code from exception.
For me it's seems a bit confusing
Steps To Reproduce
Try to upload a file larger than 30MB
Exceptions (if any)
No response
.NET Version
.NET 7, .NET 8 Preview 6
Anything else?
Tested with ASP.NET Core 7, ASP.NET Core Runtime 8.0.0-preview.6
Activity
Tratcher commentedon Jul 12, 2023
Can you enable the debug logs to get more details? The 400 is likely coming from MVC or similar.
And yes, we should fix this wherever it's being blocked.
olizarevichroman commentedon Jul 13, 2023
Sure, hope it will help. Let me know if it's not enough or maybe I did it wrong.
logs-20230713.txt
Tratcher commentedon Jul 13, 2023
There's no size exception reported here, it's a binding failure, due to an empty file name?
olizarevichroman commentedon Jul 14, 2023
@Tratcher I almost sure it's not related. Here is what server returns:
{ "errors": { "": [ "Failed to read the request form. Request body too large. The max request body size is 30000000 bytes." ] }, "type": "https://tools.ietf.org/html/rfc9110#section-15.5.1", "title": "One or more validation errors occurred.", "status": 400, "traceId": "00-5babaa18f55ab68c2d9f5302f87994cb-1316c5577cf6467d-01" }
I've maken another log and here you can see a message "Request body too large".
olizarevichroman commentedon Jul 18, 2023
@Tratcher did you have a chance to take a look?
Tratcher commentedon Jul 18, 2023
Yes, that does look like MVC catching the exception and returning a generic 400. We've talked about that before, there might be another issue about it.
michaelmartinth commentedon Mar 3, 2024
@olizarevichroman @Tratcher Is there any update regarding this issue? I also encounter a similar case where 400 is returned instead of 413.
Tratcher commentedon Mar 4, 2024
@mkArtak
jcracknell commentedon Jun 11, 2025
This is also documented in #40810 which remains unfixed. It can also occur because the ModelBinder catches and handles the IOException thrown by the server when it hangs up as a validation error (???).
aspnetcore/src/Mvc/Mvc.Core/src/ModelBinding/FormValueProviderFactory.cs
Lines 47 to 52 in 450d6ef