Kestrel Server hangs after Out of memory exception ("The connection listener failed to accept any new connections")
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 276
Description
### Is there an existing issue for this?
- [X] 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.<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
```
Contributor guide
Assessment
This issue has not been assessed yet.