dotnet / dotnet/aspnetcore

ASP requests hang if ILogger throws

Open
#10,499 13 comments 0 reactions 0 assignees View on GitHub
affected-very-few area-networking bug severity-nice-to-have
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.