-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
BadHttpRequestException: Reading the request body timed out due to data arriving too slowly #4707
Comments
@sebastienros have you worked up an FAQ wiki yet? |
I wonder if it's because if thread pool starvation... Is your application fully async? Do you have any other logs from Kestrel? Can you capture a dump or a profile? Is the application CPU bound or IO bound? |
It just happened a couple of times just earlier, usually it's happening for several successive requests in a short time.
No other warnings/errors. Probably info level but I'm not persisting those, although there is probably a way to get these.
I should be able to capture a dump from the azure portal if you think this will help? |
Any thoughts on how to get to the bottom of this issue? We're not sure if the errors are caused by legit requests. We have been getting a couple of hundreds of these per day, even though all metrics look healthy. Any particular log source that I can turn on in azure/asp.net core maybe? The stack trace doesn't give us much.
|
There was just one log entry with a slightly better call stack including some of our calling code.
The call stack is pointing to the line Then the stack below is
|
|
But the stream here is a memory stream. That's why it's using the sync version. No I/O right? The number of threads is low and metrics are healthy. |
Ah, you got me. I wasn't reading closely enough. |
How big are the posts? |
They are pretty small json payloads. Order, Customer, Product, this kind of thing... |
What size is pretty small? |
Typically under 10k characters, although there a few outliers over 100k characters. |
Are there any further logs that can be turned on to get to the bottom of this issue? |
We appear to have gotten rid of the issue. |
Using the |
Sorry I had to re-open. David, that deployment included a fix related to the IHttpContextAccessor that you help me resolved here. I incorrectly thought this might have fixed this issue as well. The call stack varies slightly when the error is captued in the log. Usually only asp.net frames, but it also sometimes happen in this new piece of code, which is very similar to the one I posted above handling webhooks: Simplified a bit for clarity:
Logged error:
I'm pretty sure that it is related to |
Here is another stack pointing clearly showing the reading of the stream is the issue:
|
@halter73 any ideas? PS: are you using that middleware in production? It’s looks terribly inefficient. |
Yes we are using this in prod. |
Do you have structured logging in place? You don't need to attach this much information to the scope, you just need enough information attached to every request so that you can find all correlated logs. You would log the body in chunks and then look at the entire payload by looking at all logs for a specific request id.
It's a DoS waiting to happen. I can just send a large payload to your application and boom, out of memory. (see https://github.com/davidfowl/AspNetCoreDiagnosticScenarios/blob/master/Scenarios/Controllers/BigJsonInputController.cs for an example). It'll also be one of the ASP.NET Core no-no (see https://github.com/davidfowl/AspNetCoreDiagnosticScenarios/blob/master/AspNetCoreGuidance.md#avoid-reading-the-entire-request-body-or-response-body-into-memory)
Yes, I've seen it enough times now that I think we should build something more efficient out of the box #3700 |
I guess you could say it is structured, yes. Also, the vast majority of requests we get are webhooks, that can take various shape (but always in json format) and we must validate that they are authentic by hashing the body.
I see how this could be a problem. Going back to the original issue, I just wanted to point out that the pattern we're seeing is that these errors occur in batch. |
What is there a difference between the following two?
|
We deployed yet again today to try to fix this.
Using We also wanted to rule temporary thread pool exhaustion (even though the thread count counter in the azure portal looks ok) because we thought that the threadpool might take time to ramp up threads, and maybe a spike of requests might cause temporary starvation.
We are running out of ideas. |
@clement911 What is your App Service scale? We are having what looks like the same issue. ASP.NET Core 2.1 app in an Azure App Service (Windows) deployment with similar behavior - fine for a few minutes, then a group of connections all throw this exception, then fine again. All request are POSTs with a JSON body that is being read and deserialized in a middleware. |
Hi @tstuts, I'm not sure if it is related to that issue, but we also noticed we have been getting a lot more of the following errors. Nowhere near as much, but we used to maybe get it once a day and now we get it a lot more, and I feel like they might be happening around the same time as the orginal issue.
|
That usually means there's thread pool starvation... Hmm |
@davidfowl I don't understand how this is possible given that Here is a screenshot from Azure Portal showing our thread count over the last 12 hours. |
200 threads is a lot more than you have cores. If those threads are all active then some of them may not be getting enough CPU time (similar to thread pool starvation). We're making some changes in the data rate timers to mitigate these scenarios. aspnet/KestrelHttpServer#3070. That said, your system is likely still overtaxed. |
Having the same issue as well. |
For those who are still experiencing the issue, did you read my post? #4707 (comment) As today, I had NO issues since over one year on two different servers. |
Any update on this issue, I am also facing the same exception. The request is pretty small but kestrel is throwing 408 with message "request arriving too slow".
|
#pragma warning disable CS4014 // 由于此调用不会等待,因此在调用完成前将继续执行当前方法
I I've seen all the discussions. Is there an effective solution now |
Is this going to get fixed in the upcoming release? |
@clement911 if moving to DB processing first would solve the ReadToEndAsync issue? or else you tried using structured class instead of reading the object from Stream instead? |
Ok, I'm started reading this thread an hour ago. Now Im here at the end of thread yet to get solution. What is the solution now for .NEt 3.1, Im having same issue |
It's because the issue has turned into lots of different issues 😄. There's no repro for this issue and it depends on the environment and client speed (at least the original issue does). We know there's an issue somewhere but it's not clean how we make progress with the information provided here. |
@Gopichandar I came across this and solved the issue as follow
seems the root cause in our case caused by all CPU being used for waiting tasks (mostly DB/IO related) to finish, and this causes the exception with BadHttpRequestException: Reading the request body timed out due to data arriving too slowly |
@davidfowl I think I was able to reproduce this issue over and over when I debugged my own code. I had made a small movie and Wireshark captures. But cannot share them here in this public github repo, what other more private channels can I reach out to you and the MS team? The longer story: After hours of investigation I found out that there was two thing I could change to make the call succeed:
The payload is ~6Kb. I don’t think it’s a thread pool issue on the server side, due I am able to reproduce it over and over and a 1 byte change in the payload size can affect the result. And the other day the server handled way more requests. I had seen error message So the question is, what is it in aspnetcore that can cause this issue ? and how do I share more data with you guys? |
It seems like I found a workaround until this gets fixed. I'll change the MTU of the first system where it doesn't work and keep this updated.
|
Thank you for contacting us. Due to a lack of activity on this discussion issue we're closing it in an effort to keep our backlog clean. If you believe there is a concern related to the ASP.NET Core framework, which hasn't been addressed yet, please file a new issue. This issue will be locked after 30 more days of inactivity. If you still wish to discuss this subject after then, please create a new issue! |
@davidfowl any chance to reopen this? Looks like rasmus-s found a repro |
@halter73 check out the latest comments |
I think its worth mentioning that sending/reading data slowly is a vector of DDoS attack |
Correct. Specifically, this is called a slowloris attack and that's exactly what this min rate timeout and resulting exception are designed to mitigate. |
I don’t think anyone is arguing that it’s not a sane default... but for applications that need to potentially receive data slowly, looking for a reliable way to disable this. |
There is, you can set the minimum data rate (the error itself has a pointer to the thing you need to change) https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.server.kestrel.core.kestrelserverlimits.minrequestbodydatarate?view=aspnetcore-5.0 |
Thank you for contacting us. Due to a lack of activity on this discussion issue we're closing it in an effort to keep our backlog clean. If you believe there is a concern related to the ASP.NET Core framework, which hasn't been addressed yet, please file a new issue. This issue will be locked after 30 more days of inactivity. If you still wish to discuss this subject after then, please create a new issue! |
We have an asp.net core 2.1 app running on .net 4.7 in azure web app service.
Recently we started getting A LOT of the following error:
Our app is under pretty constant heavy load (from incoming webhooks mostly). During big spikes, we tend to see more of these.
We used to run on asp.net core 2.0 / .net 4.6.1 for many months and we never saw that error before.
It seems to have started happening following our recent upgrade to asp.net core 2.1 / .net 4.7.
We'd like to get to the bottom of this issue, but we are not even sure where to start.
Any thoughts?
The text was updated successfully, but these errors were encountered: