-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bad error handling for IOException while reading incoming request body #749
Comments
I think 413 Payload Too Large is a better error code. What do you guys think? |
David, thanks for reporting!
You might be surprised, but Ocelot has strange error handling mechanism with status code overriding aka Http Error Status Codes (docs in source) feature. This is Tom's design. In future it should be redesigned. I don't like HTTP status codes overriding, because the actual status is lost in Ocelot core. And, I guess, Ocelot doesn't return actual code in custom response header.
What cases are you talking about?
Why Not? When do you create a PR with a bug fix? |
Agree on 413! This is the best status code to return in case of Content-Length problems with request. P.S. Don't reference Tom in chats. He doesn't read Ocelot GitHub notifications since 2020... Only current maintainers read notifications, it's me and Raynald. |
@raman-m This is issue present with latest Ocelot version too. I am able to replicate now. Was missing to configure UseHttpSys(). |
@ks1990cn I would prefer to wait for a reply from issue raiser, because I need to understand his vision and idea of fixing this bug. |
Please refer to dummy changes I made on @raman-m I respect your statement & waiting for @davidni to come with his idea on this bug. I am just trying to understand flow and understand what I can do to fix this, if anything comes up. Meanwhile I come up with following question:- On note - I can see on this stackoverflow discussion they use and define server specific only while doing on Global level. |
Sure, I am looking into it.. Just I am trying to figure out - On which hosting server current application is hosted, because Looking into aspnetcore application too, to understand how I can find this value. |
We need to fix this issue for HttpSys only, right? @davidni FYI |
@raman-m The error handling is hiding the 413 exception payload too large. I've tested this with Kestrel, it's throwing a catch (BadHttpRequestException badHttpRequest)
{
return badHttpRequest.StatusCode == 413 ? new ErrorResponse<HttpRequestMessage>(new PayloadTooLargeError(badHttpRequest)) : new ErrorResponse<HttpRequestMessage>(new UnmappableRequestError(badHttpRequest));
} |
…est body (#1769) * Adding "quick and..." fix to the payload too large exception, adding two acceptance tests for kestrel and http sys. * skipping test if platform is not windows * Moving Payload too large error to HttpExceptionErrorMapper. A review of the exception handling is needed. * Fix issues after merge in Steps.cs * using collection expression here * Code review by @raman-m --------- Co-authored-by: Raman Maksimchuk <[email protected]>
Expected Behavior
If an
IOException
happens while reading the incoming request body (inRequestMapper.MapContent
here), Ocelot fails the request with anUnmappableRequestError
and status code 404.404 is not appropriate, and the error logged by ocelot should be more specific than
UnmappableRequestError
. It just so happens that the exception happens while doing request mapping, but it's really an IO problem while reading the incoming request stream. Response status shouldn't be 404. In the case of too large request, 400 might be appropriate. In other cases, something in the 5xx range.Steps to Reproduce the Problem
This happens consistently, for example, for requests that are too large for the server (
HttpSys
throws an IOException if the Content-Length of the incoming request is larger than 30MB by default -- see: AspNetCore source).Ocelot returns 404, and logs
UnmappableRequestError
.Specifications
The text was updated successfully, but these errors were encountered: