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 Server hangs after Out of memory exception ("The connection listener failed to accept any new connections")

See original GitHub issue

Is 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:open
  • Created a year ago
  • Reactions:1
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Sergey-Terekhincommented, Sep 10, 2022

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

1reaction
davidfowlcommented, May 6, 2022

This is a good one! I’m pretty sure I wrote that comment…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Request draining with ASP.NET Core Kestrel web server
Creating new connections can be slow and expensive. There's no guarantee that the client has read the response before the connection closes.
Read more >
How do I get the kestrel web server to listen to non- ...
I've deployed my c#, asp.net 5, mvc 6 app to a windows 2008 server. I've fired up dnx web and it is listening...
Read more >
How the Asp Core Web Server Kestrel Hangs Up Fatal
502 - Web server received an invalid response while acting as a gateway or proxy server. There is a problem with the page...
Read more >
You're using HttpClient wrong and it is destabilizing your ...
Unable to connect to the remote server ; System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port) ...
Read more >
Avoiding the Top 10 NGINX Configuration Mistakes
We help you avoid the 10 most common NGINX configuration errors, explaining the problems caused by each and how to fix them.
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