Skip to content

Kestrel accept loop stops randomly and application stops processing new requests after migrating to dotnet 8/9 from dotnet 6. #64931

@Piyush-022

Description

@Piyush-022

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

After upgrading from .NET 6 to .NET 8/9, our ASP.NET Core application intermittently enters a “frozen” state in production where:

  • The process remains alive (no crash, no restart)
  • CPU usage drops to ~0%
  • Memory usage remains stable
  • The application stops accepting and processing new requests

A process dump taken during this state shows that Kestrel’s accept/dispatcher loop is no longer running (async accept loop state machines are missing), while the listening socket still exists and is marked as listening. as a result IIS started giving 502.3 as kestrel was not processing new proxied requests from IIS. The only way to recover application is restarting the app pool.

we are hosting application behind IIS using out-of-process model and ANCM.

This issue occurs rarely and randomly under productions random scenarios and load and has not been reproducible locally. First this issue happened in production env after 7-8 hours of deploying application with dotnet 8 over there. then we reverted application back to dotnet 6. and then we gave it second try and migrated to dotnet 9, but same issue happened after 15-20 days. this happened once again after 10 days of first occurrence.
nothing can be seen in event viewer as well. also the dump we have generated is with dotnet 9 only (from test environment). we don't have dump of process froze in production with dotnet 8.

Expected Behavior

Application should keep processing new requests as dotnet 6 because same application code was working perfectly with 6.

Steps To Reproduce

We are also not able to reproduce as this is very random.

Exceptions (if any)

Also got below kestrel related exception 4 times just before application stopped processing new requests. all these 4 exception thrown in span of milliSeconds.
{
"exception": {
"Message": "A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread.",
"HResult": -2146233088,
"ClassName": "System.AggregateException",
"InnerException": {
"StackTraceString": " at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.TransportConnectionManager.RemoveConnection(Int64 id)\r\n at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.KestrelConnection1.ExecuteAsync()", "Message": "No value found for the specified id.", "HResult": -2147024809, "ClassName": "System.ArgumentException", "RemoteStackIndex": 0, "Source": "Microsoft.AspNetCore.Server.Kestrel.Core", "ParamName": "id" }, "RemoteStackIndex": 0, "InnerExceptions": [ { "Message": "No value found for the specified id.", "RemoteStackIndex": 0, "Source": "Microsoft.AspNetCore.Server.Kestrel.Core", "StackTraceString": " at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.TransportConnectionManager.RemoveConnection(Int64 id)\r\n at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.KestrelConnection1.ExecuteAsync()",
"HResult": -2147024809,
"ClassName": "System.ArgumentException",
"ParamName": "id"
}
]
},
"data": {
"message": {
"data": "A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (No value found for the specified id. (Parameter 'id'))"
}
}
}

Also at the same time i got one occurrence of below exception as well. This is related to outgoing HTTP2 request

{
"exception": {
"Message": "A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread.",
"HResult": -2146233088,
"ClassName": "System.AggregateException",
"InnerException": {
"StackTraceString": " at System.Threading.Overlapped.GetOverlappedFromNative(NativeOverlapped* pNativeOverlapped)\r\n at System.Threading.Overlapped.Free(NativeOverlapped* nativeOverlappedPtr)\r\n at System.Net.Sockets.SocketAsyncEventArgs.Dispose()\r\n at System.Net.Sockets.Socket.Dispose(Boolean disposing)\r\n at System.Net.Sockets.NetworkStream.Dispose(Boolean disposing)\r\n at System.IO.Stream.Close()\r\n at System.Net.Security.AuthenticatedStream.Dispose(Boolean disposing)\r\n at System.Net.Security.SslStream.Dispose(Boolean disposing)\r\n at System.IO.Stream.Close()\r\n at System.Net.Http.Http2Connection.FinalTeardown()\r\n at System.Net.Http.Http2Connection.ReleaseStream()\r\n at System.Net.Http.Http2Connection.RemoveStream(Http2Stream http2Stream)\r\n at System.Net.Http.Http2Connection.Http2Stream.Complete()\r\n at System.Net.Http.Http2Connection.Http2Stream.Cancel()\r\n at System.Net.Http.Http2Connection.Http2Stream.OnReset(Exception resetException, Nullable1 resetStreamErrorCode, Boolean canRetry)\r\n at System.Net.Http.Http2Connection.Abort(Exception abortException)\r\n at System.Net.Http.Http2Connection.ProcessIncomingFramesAsync()", "Message": "Handle is not initialized.", "HResult": -2146233079, "ClassName": "System.InvalidOperationException", "RemoteStackIndex": 0, "Source": "System.Private.CoreLib" }, "RemoteStackIndex": 0, "InnerExceptions": [ { "StackTraceString": " at System.Threading.Overlapped.GetOverlappedFromNative(NativeOverlapped* pNativeOverlapped)\r\n at System.Threading.Overlapped.Free(NativeOverlapped* nativeOverlappedPtr)\r\n at System.Net.Sockets.SocketAsyncEventArgs.Dispose()\r\n at System.Net.Sockets.Socket.Dispose(Boolean disposing)\r\n at System.Net.Sockets.NetworkStream.Dispose(Boolean disposing)\r\n at System.IO.Stream.Close()\r\n at System.Net.Security.AuthenticatedStream.Dispose(Boolean disposing)\r\n at System.Net.Security.SslStream.Dispose(Boolean disposing)\r\n at System.IO.Stream.Close()\r\n at System.Net.Http.Http2Connection.FinalTeardown()\r\n at System.Net.Http.Http2Connection.ReleaseStream()\r\n at System.Net.Http.Http2Connection.RemoveStream(Http2Stream http2Stream)\r\n at System.Net.Http.Http2Connection.Http2Stream.Complete()\r\n at System.Net.Http.Http2Connection.Http2Stream.Cancel()\r\n at System.Net.Http.Http2Connection.Http2Stream.OnReset(Exception resetException, Nullable1 resetStreamErrorCode, Boolean canRetry)\r\n at System.Net.Http.Http2Connection.Abort(Exception abortException)\r\n at System.Net.Http.Http2Connection.ProcessIncomingFramesAsync()",
"Message": "Handle is not initialized.",
"HResult": -2146233079,
"ClassName": "System.InvalidOperationException",
"RemoteStackIndex": 0,
"Source": "System.Private.CoreLib"
}
]
}

What i understand is that non of the above exception should come because of out application code. i can be wrong here as well.

.NET Version

8.0.3 and 9.0.3

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