Skip to content

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

@shaynevanasperen

Description

@shaynevanasperen

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions