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.

ASP requests hang if ILogger throws

See original GitHub issue

Description

ASP.NET requests hang indefinitely if the ILogger being used throws a NotImplementedException from the BeginScope method.

To Reproduce

Steps to reproduce the behavior: Repro can be found in minimal repository here: https://github.com/jroggeman/aspnetbug

Basic overview:

  1. Using ASP.NET Core 2.2.204
  2. Create a new ASP.NET web application
  3. Create a new dotnet standard library (netstandard2.0)
  4. In the library, implement a minimal console logger and provider using ILogger and ILoggerProvider interface. Make sure BeginScope method throws a NotImplementedException
  5. In the web app, register the provider and inject it in to the default controller
  6. dotnet run the app and request a page from the controller

Observe that the request will hang indefinitely with no output from ASP

Expected behavior

An error is indicated somehow - a 500 is returned from ASP, ASP prints a stack trace,

Additional context

I understand you probably shouldn’t inject incomplete implementations of interfaces into ASP 😃 We’ve stopped doing that and all is fine. But I would also expect that ASP would realize that this was an error somehow and handle it, rather than hanging the request. So just in case this type of issue is more pervasive, I figured I’d throw it over to you all.

dotnet info:

.NET Core SDK (reflecting any global.json):
 Version:   2.2.204
 Commit:    8757db13ec

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

Host (useful for support):
  Version: 2.2.5
  Commit:  0a3c9209c0

.NET Core SDKs installed:
  2.1.602 [C:\Program Files\dotnet\sdk]
  2.1.604 [C:\Program Files\dotnet\sdk]
  2.2.202 [C:\Program Files\dotnet\sdk]
  2.2.204 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

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

Edit: Repo link for bug repro was committed one level too deep so was missing the actual logging library. Fixed now.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
analogrelaycommented, May 28, 2019

Let’s at a minimum look at making sure that Kestrel/IIS kill the connection when CreateContext throws. Logging is really hard here because we don’t know if it’ll work.

1reaction
analogrelaycommented, May 24, 2019

I think we should consider what happens when things in IHttpApplication.CreateContext throw. This goes a little beyond Logging since it’s just the thing causing the problem here. We seem to hang the entire request, and not report anything at all.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Unable to resolve service for type 'Microsoft.Extensions ...
I created an ASP.NET Core 3.0 Web Application with the default template in Visual Studio 2019 Preview 2.2 and tried to inject an...
Read more >
Diagnosing an ASP.NET Core hard crash
The first of these causes an InvalidOperationException to be thrown. The second and third, between them, cause the app to crash. The debugger ......
Read more >
How to work with Hangfire in ASP.NET Core
Background jobs: Hangfire allows you to define jobs or activities that need to run in the background, independent of the user's request.
Read more >
Dealing with Exceptions
When Hangfire encounters external exception that occurred during the job performance, it will automatically try to change its state to the Failed one,...
Read more >
Make HTTP requests using IHttpClientFactory in ASP.NET ...
Calls EnsureSuccessStatusCode to throw an exception if the response status code doesn't indicate success. HttpClient also supports other types ...
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