question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Kestrel stops listening/responding to requests after some time (only after updating to .NET 7.0)

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I have a Web Application which runs some background services and hosts some UI pages using Razor Pages. It was working perfectly fine on .NET 6.0, but after simply updating the target framework to net7.0 and redeploying to a folder on my machine, I started to encounter this problem.

Immediately after deploying the application, it works fine and continues to respond to requests from my browsers (Firefox, Chrome, Edge). But anywhere from 10 minutes to 6 hours later, the site no longer responds to HTTP requests (hitting refresh in my browser results in the connection timing out), and then it stays this way until I stop and restart it from the command line.

I have tried several things to attempt to narrow down the problem, but everything I have tried has failed. It’s extremely difficult to do this because I have to wait so long between each try. As soon as I revert the target framework back to .NET 6.0, the problem goes away again and the site remains responsive permanently. So unfortunately I am unable to produce a minimalistic project which reproduces the issue.

I have a Prometheus /metrics endpoint exposed through the application and I have Grafana Agent configured on my machine to scrape the metrics every 15 seconds (from http://localhost/metrics). I have a branch in my request pipeline to exclude that endpoint from Authorization. The rest of the application is secured with MicrosoftIdentity authentication pointing to my Azure Active Directory tenant using the OpenIdConnect authentication scheme.

The really strange thing is that when the browser requests start to show connection timeouts, my Grafana Agent scraper is still able to scrape the /metrics endpoint every 15 seconds, which I can confirm from the logs. Here is a snippet from my Program.cs:

builder.WebHost.UseUrls($"https://{DomainName}", $"http://{DomainName}", "http://localhost");

if (!builder.Environment.IsDevelopment())
    builder.Services
        .AddLettuceEncrypt(LetsEncrypt.Options.Configure)
        .PersistCertificatesToAzureKeyVault(LetsEncrypt.AzureKeyVault.Configure);

builder.Services
    .AddRazorPages()
    .AddMicrosoftIdentityUI();

builder.Services
    .AddAuthorization(options => options.FallbackPolicy = options.DefaultPolicy)
    .AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
    .AddMicrosoftIdentityWebApp(Authentication.MicrosoftIdentity.Configure);

I’ve tried disabling all my background sevices, and I even tried disabling authentication/authorization completely, and using self-signed certificates instead of LetsEncrypt, but none of these have had any effect.

Expected Behavior

The web application should continue to respond to HTTP requests indefinitely.

Steps To Reproduce

Host a .NET 7.0 Razor Pages web application on Windows 11. Wait for the site to stop responding to HTTP requests.

Exceptions (if any)

Nothing. Logs show nothing either.

.NET Version

7.0.100

Anything else?

No response

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:32 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
danmoseleycommented, Nov 24, 2022

The VS creds issue should be unrelated - please report it though the VS feedback button so they can help with that.

1reaction
Tratchercommented, Nov 22, 2022

Once you have the dump, open it in VS and look at the threads window for blocked threads, and the parallel tasks window for blocked tasks. That should give you an idea of where things are stalling.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Request draining with ASP.NET Core Kestrel web server
Draining the request body means reading and discarding the data without processing it. The draining process makes a tradeoff between allowing ...
Read more >
Configure options for the ASP.NET Core Kestrel web server
If the app attempts to configure the limit on a request after it starts to read the request, an exception is thrown.
Read more >
Stop Kestrel server accepting requests from code
I am trying to accomplish the following: I have a asp.net core 3.1 running a gRPC service. During the lifetime of the application...
Read more >
Why isn't my ASP.NET Core app in Docker working?
In this post I describe a problem where my ASP.NET Core app in Docker wasn't responding to requests. This post debugs and diagnoses...
Read more >
Kestrel: The Microsoft web server you should be using
As Kestrel doesn't run until your ASP.NET Core code runs, this is a relatively easy way to make server configuration dynamic, with any...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found