Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BadHttpRequestException: Reading the request body timed out due to data arriving too slowly. See MinRequestBodyDataRate on ASP.NET core 2.2

I'm using aspnetboilerplate solution developed with ASP.NET core 2.2 . The backend is deployed on azure and it uses the SQL server provided.

Sometimes, when the backend has a lot of requests to handle, it logs this exception:

ERROR 2020-11-20 12:28:21,968 [85 ] Mvc.ExceptionHandling.AbpExceptionFilter - Reading the request body timed out due to data arriving too slowly. See MinRequestBodyDataRate. Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException: Reading the request body timed out due to data arriving too slowly. See MinRequestBodyDataRate.

I tried to solve this problem adding this code to my Program.cs

 namespace WorkFlowManager.Web.Host.Startup
    {
        public class Program
        {
            public static void Main(string[] args)
            {
                var host = new WebHostBuilder()
                    .UseKestrel(options =>
                    {
                        options.Limits.MinResponseDataRate = null;
                    });
    
                BuildWebHost(args).Run();
            }
    
            public static IWebHost BuildWebHost(string[] args)
            {
                return WebHost.CreateDefaultBuilder(args)
                    .UseStartup<Startup>()
                    .Build();
            }
        }
    }

But the problem is not solved.

like image 411
C1X Avatar asked Dec 13 '22 07:12

C1X


1 Answers

The exception you have shared indicates that application has a problem while "reading" the request.

Reading the request body timed out due to data arriving too slowly. See MinRequestBodyDataRate.

But you are trying to set MinResponseDataRate.

Please consider to update MinRequestBodyDataRate.

And instead of setting value to null, please examine the documentation and try to set meaningful values for request.

Default values are:

The default minimum rate is 240 bytes/second with a 5 second grace period.

And you can change like this:

.UseKestrel(options =>
    {
        options.Limits.MinRequestBodyDataRate =
            new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(10));
    });
like image 169
Ozan Aydın Avatar answered Jan 22 '23 02:01

Ozan Aydın