Skip to content

[ASPNET Core 2.1] src\SignalR\clients\csharp\Http.Connections.Client\src\HttpConnection.cs should null check logging scope before disposing #47470

@arianmotamedi

Description

@arianmotamedi

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

HttpConnection.cs in SignalR client (aspnet core 2.1) is disposing its ILogger.Scope object without doing a null check. LoggerExtensions.BeginScope<>() documentation says this method may return null, so it needs to be properly null checked before calling .Dispose() on it otherwise it throws a null ref exception at runtime.

Expected Behavior

_scopeDisposable should be null-checked before disposing.

Steps To Reproduce

For whatever reason, the scope isn't null in Microsoft.Extensions.Logging 2.2 even though the docs say this version could still return null. We can see this when running Microsoft.AspNetCore.SignalR.Client.Tests.HttpConnectionTests+Negotiate.NegotiateReturnedConenctionIdIsSetOnConnection test - as it's using LogSinkLogger, which returns null in its BeginScope() override.

Upgrading Microsoft.Extensions.Logging references and its dependencies to 3.1 is correctly calling the override and returning null, but that dispose method above throws a null ref exception at runtime.

Exceptions (if any)

No response

.NET Version

4.6.2

Anything else?

ASPNET Core 2.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-signalrIncludes: SignalR clients and servers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions