Skip to content
This repository has been archived by the owner on Jul 5, 2020. It is now read-only.

Replace non-threadsafe HashSet with ConcurrentDictionary in RequestTrackingTelemetryModule.IsHandlerToFilter #1211

Merged
merged 2 commits into from Jun 4, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 5 additions & 7 deletions Src/Web/Web.Shared.Net/RequestTrackingTelemetryModule.cs
Expand Up @@ -28,11 +28,9 @@ public class RequestTrackingTelemetryModule : ITelemetryModule
private TelemetryConfiguration telemetryConfiguration;
private bool initializationErrorReported;
private ChildRequestTrackingSuppressionModule childRequestTrackingSuppressionModule = null;

/// <summary>
/// Handler types that are not TransferHandlers will be included in request tracking.
/// </summary>
private HashSet<Type> requestHandlerTypesDoNotFilter = new HashSet<Type>();

/// <summary>Tracks if given type should be included in telemetry. ConcurrentDictionary is used as a concurrent hashset.</summary>
private ConcurrentDictionary<Type, bool> includedHttpHandlerTypes = new ConcurrentDictionary<Type, bool>();
Mikhail-msft marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Gets or sets a value indicating whether child request suppression is enabled or disabled.
Expand Down Expand Up @@ -371,7 +369,7 @@ private bool IsHandlerToFilter(IHttpHandler handler)
if (handler != null)
{
var handlerType = handler.GetType();
if (!this.requestHandlerTypesDoNotFilter.Contains(handlerType))
if (!this.includedHttpHandlerTypes.ContainsKey(handlerType))
{
var handlerName = handlerType.FullName;
foreach (var h in this.Handlers)
Expand All @@ -383,7 +381,7 @@ private bool IsHandlerToFilter(IHttpHandler handler)
}
}

this.requestHandlerTypesDoNotFilter.Add(handlerType);
this.includedHttpHandlerTypes.TryAdd(handlerType, true);
}
}

Expand Down