Open stg609 opened 4 years ago
Do you get the 504 without fiddler running?
Those logs are showing the expected behavior.
ConsumeAsync
) needs to drain the existing request off the wire in order to process the next request. It's too big, so the only thing it can do is close the connection.2 and 3 do lead to a race condition where the client may or may not receive and process the 500 response before the connection gets closed. There's not much kestrel can do about this, it depends both on the timing, and on how the client processes responses.
@davidfowl No, most of the time the client will throw an exception said the connection was broken. I only find the 504 with fiddler.
@Tratcher Thanks for the explanation. Now I know the reason why the connection is closed. However, I still think it's not a good behavior.
And as a Api developer, I'm expecting there's some workarounds to help me return consistent response to my client.
We'll have to investigate the response flushing in Kestrel to see if we can ensure it goes out before the drain error happens.
You might also want to try this using HTTP/2. The mechanics are quite different and I think it would work there.
Describe the bug
Use the RequestSizeLimitAttribute together with IFormFile on an WebApi action method. The expected behaviour when the request body is too large is to return a 500 internal server error and tell me the request body is too large. However, if the client frequently (e.g. 1 request each second) send files larger than the limit, the kestrel will probably return 504 with 0 byte in response.
To Reproduce
It's very easy to reproduce.
I also upload the code here: https://github.com/stg609/Issue23840
Exceptions (if any)
Postman
I get below snapshot using Postman.
Fiddler
I get below snapshot using Fiddler to send the request, as you can see, there're multiple 504 response.
And the raw response :
Further technical details
dotnet --info
The IDE (VS / VS Code/ VS4Mac) you're running on, and it's version Visual Studio 2019 16.6
The .Net Core Log for the exception if needed.