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 ASP.NET applications throws various exceptions when benchmarked

See original GitHub issue

Describe the bug

If I create a brand new ASP.NET Core 3.1 Web application project (Visual studio 16.7.4) and then do the following:

  • Use the empty template (to get the WeatherForecast.cs example, no Docker, no authentication, no HTTPS) (So I get the “Hello World” in startup.cs example)

Nothing else, then I start a simple benchmark against the running web application (using Kestrel, not IIS Express) (in debug or release mode)

using a simple benchmark like apache benchmark

ab -c 100 -n 1000 http://localhost:5000/weatherforecast

or NBomber I get tons of exceptions logged in Visual Studio Output/Debug window as shown below.

This is an unexpected behavior as we all know exception are expensive, so what do I do wrong here?

Even with 1 concurrent request, I get the same errors. When I run ab, I don’t get any failed requests:

ab -c 1 -n 100 http://localhost:5000/

returns

Server Software: Kestrel Server Hostname: localhost Server Port: 5000

Document Path: / Document Length: 12 bytes

Concurrency Level: 1 Time taken for tests: 2.991 seconds Complete requests: 100 Failed requests: 0 Total transferred: 10400 bytes HTML transferred: 1200 bytes Requests per second: 33.44 [#/sec] (mean) Time per request: 29.909 [ms] (mean) Time per request: 29.909 [ms] (mean, across all concurrent requests) Transfer rate: 3.40 [Kbytes/sec] received

With IIS Express Running with IIS Express I get no errors like this in the Debug -> Output window, all I get there is a bunch of statements, like:

The thread 0x529c has exited with code 0 (0x0). The thread 0x4c84 has exited with code 0 (0x0). The thread 0x6430 has exited with code 0 (0x0). The thread 0x3b60 has exited with code 0 (0x0).

Perhaps IIS Express hides these exceptions?

Exceptions (if any)

Exception thrown: ‘System.ObjectDisposedException’ in System.Net.Sockets.dll Exception thrown: ‘System.ObjectDisposedException’ in System.Private.CoreLib.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in System.Private.CoreLib.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in System.Private.CoreLib.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in System.Private.CoreLib.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.dll Exception thrown: ‘System.ObjectDisposedException’ in System.Net.Sockets.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in System.Private.CoreLib.dll Exception thrown: ‘System.ObjectDisposedException’ in System.Private.CoreLib.dll Exception thrown: ‘System.ObjectDisposedException’ in System.Net.Sockets.dll Exception thrown: ‘System.ObjectDisposedException’ in System.Private.CoreLib.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in System.Private.CoreLib.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in System.Private.CoreLib.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in System.Private.CoreLib.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in System.Private.CoreLib.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in System.Private.CoreLib.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in System.Private.CoreLib.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in System.Private.CoreLib.dll Exception thrown: ‘System.ObjectDisposedException’ in System.Net.Sockets.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.dll Exception thrown: ‘System.ObjectDisposedException’ in System.Private.CoreLib.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in System.Private.CoreLib.dll Exception thrown: ‘System.ObjectDisposedException’ in System.Net.Sockets.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.dll Exception thrown: ‘System.ObjectDisposedException’ in System.Private.CoreLib.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in System.Private.CoreLib.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in System.Private.CoreLib.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in System.Private.CoreLib.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in System.Private.CoreLib.dll

With trace log level:

Microsoft.AspNetCore.Mvc.Infrastructure.DefaultOutputFormatterSelector: Debug: Could not find an output formatter based on content negotiation. Accepted types were (text/html) Exception thrown: ‘Microsoft.AspNetCore.Connections.ConnectionResetException’ in System.Private.CoreLib.dll

Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Debug: Executing controller factory for controller BenchmarkAPI.Controllers.WeatherForecastController (BenchmarkAPI) Exception thrown: ‘Microsoft.AspNetCore.Connections.ConnectionResetException’ in System.Private.CoreLib.dll

Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets: Debug: Connection id “0HM34CJP6C9BJ” sending FIN because: “The client closed the connection.” Exception thrown: ‘Microsoft.AspNetCore.Connections.ConnectionResetException’ in System.Private.CoreLib.dll

Microsoft.AspNetCore.HostFiltering.HostFilteringMiddleware: Trace: All hosts are allowed. Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Trace: Result Filter: Before executing OnResultExecuting on filter Microsoft.AspNetCore.Mvc.Infrastructure.ClientErrorResultFilter. Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets: Debug: Connection id “0HM34CJP6C9BJ” sending FIN because: “The client closed the connection.” Exception thrown: ‘Microsoft.AspNetCore.Connections.ConnectionResetException’ in System.Private.CoreLib.dll Microsoft.AspNetCore.Server.Kestrel: Debug: Connection id “0HM34CJP6C9BI” stopped.

Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets: Debug: Connection id “0HM34CJP6C9BR” received FIN. Exception thrown: ‘System.Net.Sockets.SocketException’ in Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.dll Microsoft.AspNetCore.Routing.Matching.DfaMatcher: Debug: 1 candidate(s) found for the request path ‘/weatherforecast’

Exception thrown: ‘System.Net.Sockets.SocketException’ in System.Private.CoreLib.dll Exception thrown: ‘System.Net.Sockets.SocketException’ in Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.dll

Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Trace: Action Filter: Before executing OnActionExecuting on filter Microsoft.AspNetCore.Mvc.Infrastructure.ModelStateInvalidFilter. Exception thrown: ‘System.ObjectDisposedException’ in System.Net.Sockets.dll Microsoft.AspNetCore.Server.Kestrel: Debug: Connection id “0HM34CCASENB5” started. Exception thrown: ‘System.ObjectDisposedException’ in System.Private.CoreLib.dll

Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Trace: Result Filter: After executing OnResultExecuting on filter Microsoft.AspNetCore.Mvc.Infrastructure.ClientErrorResultFilter. Exception thrown: ‘System.ObjectDisposedException’ in System.Net.Sockets.dll Microsoft.AspNetCore.Server.Kestrel: Debug: Connection id “0HM34CCASENB2” started.

Exception thrown: ‘System.ObjectDisposedException’ in System.Net.Sockets.dll Exception thrown: ‘System.ObjectDisposedException’ in System.Private.CoreLib.dll

Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request finished in 486.199ms 200 application/json; charset=utf-8 Microsoft.AspNetCore.Server.Kestrel: Debug: Connection id “0HM34CCASENBA” disconnecting. Microsoft.AspNetCore.Server.Kestrel: Debug: Connection id “0HM34CCASENB6” disconnecting. Microsoft.AspNetCore.Server.Kestrel: Debug: Connection id “0HM34CCASENBA” stopped. Microsoft.AspNetCore.Server.Kestrel: Debug: Connection id “0HM34CCASENB6” stopped. Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets: Debug: Connection id “0HM34CCASENBA” sending FIN because: “The Socket transport’s send loop completed gracefully.” Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets: Debug: Connection id “0HM34CCASENB6” sending FIN because: “The Socket transport’s send loop completed gracefully.” Exception thrown: ‘System.ObjectDisposedException’ in System.Net.Sockets.dll Microsoft.AspNetCore.Server.Kestrel: Debug: Connection id “0HM34CCASENB2” disconnecting.

Further technical details

ASP.NET Core 3.1 Visual Studio 16.7.4

dotnet --info .NET Core SDK (reflecting any global.json): Version: 3.1.402 Commit: 9b5de826fd

Runtime Environment: OS Name: Windows OS Version: 10.0.18363 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.1.402\

Host (useful for support): Version: 3.1.8 Commit: 9c1330dedd

.NET Core SDKs installed: 2.2.207 [C:\Program Files\dotnet\sdk] 3.1.300 [C:\Program Files\dotnet\sdk] 3.1.402 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
JoeMarkovcommented, Nov 13, 2020

Just tried again using latest visual Studio 2019 16.8.0 and .NET Core 3.1 and .NET 5 and I was no longer able to reproduce it. thanks!

1reaction
sebastienroscommented, Sep 29, 2020

Our exceptions are due to connections closed on the client side when the benchmark ends. And it looks like it’s the same thing here, as written in the trace.

Technically it’s not an issue, however maybe it would be better to handle disconnections in a more graceful way on server side? But I’ll let others comment on that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Performance improvements in ASP.NET Core 7
Not throwing exceptions resulted in reduced CPU usage in our connection close benchmarks.
Read more >
Diagnosing an ASP.NET Core hard crash
The immediate crash was due to an exception being thrown in an async void method. Relevant threading aspects: I start the ASP.NET Core...
Read more >
Why ASP.Net kestrel benchmark of 1 mil requests/sec ...
Yes, but it's worse than that: there's no fixed ratio between the performance of plain text benchmark and "a normal web application". Further ......
Read more >
Centralized exception handling and request validation in ...
Let's start with exception handling. ASP.NET Core exposes a feature called IExceptionHandlerFeature which you can use to globally handle ...
Read more >
Kestrel server crashes on exception
Crashing the process usually means: An exception thrown from: an async void method in your code; A background thread. A stackoverflow exception.
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