-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
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:
https://github.com/dotnet/aspnetcore/blob/1e8fe7e4ba93935ebc10aee6ef2a4d2b3b0c05d9/src/Middleware/ConcurrencyLimiter/src/ConcurrencyLimiterEventSource.cs#L47
https://github.com/dotnet/aspnetcore/blob/1e8fe7e4ba93935ebc10aee6ef2a4d2b3b0c05d9/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionsEventSource.cs#L46