Kestrel Server hangs after Out of memory exception ("The connection listener failed to accept any new connections")
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Describe the bug
Hi! I have an ASP.NET Core 5.0 application running in Docker in Kubernetes, which handles Web Socket connections. Each instance uses about 1Gb of memory. Sometimes, load increases and we get Out of memory exceptions, a process crashes and then is restarted by Kubernetes. But once we faced an issue that our application has just stopped to accept new connections, and the process hasn’t been crashed. The last message from instance was: “The connection listener failed to accept any new connections”, which is logged here https://github.com/dotnet/aspnetcore/blob/main/src/Servers/Kestrel/Core/src/Internal/ConnectionDispatcher.cs#L67 with a comment that describes the situation 😃
Expected Behavior
I think that the process should crash like with another unhandled exceptions, because Kestrel can not accept new connections anyway
Steps To Reproduce
No response
Exceptions (if any)
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketConnection..ctor(Socket socket, MemoryPool`1 memoryPool, PipeScheduler transportScheduler, ISocketsTrace trace, Nullable`1 maxReadBufferSize, Nullable`1 maxWriteBufferSize, Boolean waitForData, Boolean useInlineSchedulers)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketConnectionListener.AcceptAsync(CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.ConnectionDispatcher`1.<>c__DisplayClass9_0.<<StartAcceptingConnectionsCore>g__AcceptConnectionsAsync|0>d.MoveNext()
.NET Version
.NET 5.0.15
Anything else?
PS. We are using health checks, but they are listening at another port (“internal”), and in this situation they still respond with 200 OK
build info:
os_version: Linux 5.5.17-050517-generic #202004130833 SMP Mon Apr 13 12:37:30 UTC 2020
runtime_version: .NET 5.0.15
target_framework: .NETCoreApp,Version=v5.0
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:6 (5 by maintainers)
The same story in containers with memory limit. Now we add custom middleware to handle OOM and fail process, but I’d prefer it as embedded behaviour in Kestrel
This is a good one! I’m pretty sure I wrote that comment…