Skip to content

NRE in Kestrel Telemetry EventSources #44817

@Tratcher

Description

@Tratcher

Mirror of dotnet/runtime#77434

EventSource.IsEnabled() may start returning true before the OnEventCommand completes.
We initialize shared EventCounter instances in OnEventCommand that we then use from instrumented code paths.

If the EventSource is initialized before being enabled, and the instance is accessed from multiple threads, a thread could see IsEnabled() == true and then read a null EventCounter instance.
This race condition only appears once per process.

I believe this is the cause of an exception YARP hit in CI:

System.NullReferenceException : Object reference not set to an instance of an object.
   at System.Net.Http.HttpTelemetry.Http11RequestLeftQueue(Double timeOnQueueMilliseconds)
   at System.Net.Http.HttpConnectionPool.GetHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)

We should fix these cases.

cc: @Tratcher aspnetcore has 2 such cases as well:


An internal customer hit something similar:
MicrosoftTeams-image (1)

MicrosoftTeams-image (2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsfeature-kestrel

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions