1

So I have the following simple code:

namespace MyApp
{
    public class Startup
    {
        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
        {
            app.Run(async context => {
                context.Response.StatusCode = 200;
                context.Response.ContentLength = 4;
                await context.Response.WriteAsync("test");
            });
        }
    }

    public static class Program
    {
        public static void Main(string[] args)
        {
            var app = WebHost.CreateDefaultBuilder(args)
                .UseKestrel(options => {
                    options.Listen(IPAddress.Loopback, 5000);
                    options.AllowSynchronousIO = false;
                })
                .UseStartup<Startup>()
                .Build();
            app.Run();
        }
    }
}

I'm running the server via

$ dotnet run

and then I've tried to test it:

$ ab -p test.json -n 20000 -c 100 http://127.0.0.1:5000/

The json file is a small {"test": 1} string.

At the begining requests are handled blazingly fast as expected. But the more requests I fire the slower Kestrel gets. At some point (usually just after 16k requests are processed) it hangs and ab tool times out.

Interestingly if I wait few second and run ab again it works exactly the same. At some point (somewhere after 3/4 of requests) it hangs and times out. So it looks like Kestrel automagically takes care of "hanging" requests at some point and is again ready to go only to get blocked again.

I've increased the maximum open file descriptors limit to 100000 but this didn't affect the behaviour at all. I also played with Kestrel options but the result was still the same.

What is causing that? And how can I fix it?

I'm using macOS High Sierra 10.13.2 with dotnet core version 2.1.3. Is that behaviour macOS related?

EDIT: I'm closing my own question. This actually is a macOS issue.

freakish
  • 54,167
  • 9
  • 132
  • 169
  • I am experiencing kestrel hanging when moving my .net core development to MacOS on BigSur. I know it's been a while, but can you point out how you knew it was a Mac issue, so that I can go there and look? Thank you in advance. – Dan Chase Jul 27 '21 at 20:18
  • @DanChase Sorry, I vaguely remember the issue. I don't even own mac anymore. I think I followed ideas in the linked answer: some netstat and sysctl monitoring. Playing around with ephemeral ports and timeouts. And it helped so I was sure it is macOS issue. But I can't really help you beyond that. – freakish Jul 28 '21 at 09:05

0 Answers0