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

Multiple threads enumerating through a collection is intrinsically not a thread-safe procedure #76

Closed
OlegUfaev opened this issue Apr 25, 2016 · 2 comments
Assignees
Labels
Milestone

Comments

@OlegUfaev
Copy link

In our project on .NET 4.5 (ASP.NET Web-application for hosting WCF-service) used references to these NuGet-packages:

  • Microsoft.ApplicationInsights 1.2.3
  • Microsoft.ApplicationInsights.Agent.Intercept 1.2.1
  • Microsoft.ApplicationInsights.DependencyCollector 1.2.3
  • Microsoft.ApplicationInsights.JavaScript 0.15.0-build58334
  • Microsoft.ApplicationInsights.PerfCounterCollector 1.2.3
  • Microsoft.ApplicationInsights.Web 1.2.3
  • Microsoft.ApplicationInsights.WindowsServer 1.2.3
  • Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel 1.2.3

We have rarely occurring issue, which lead to 100% CPU load.
When it happened again, we have made the process dump and used DebugDiag to find/diagnose the problem.

Here the result of the "Analysis report":

The following threads in w3wp.DMP are enumerating a System.Collections.Generic.Dictionary object:
Multiple threads enumerating through a collection is intrinsically not a thread-safe procedure. If the dictionary object accessed by these threads is declared as static then the threads can go in an infinite loop while trying to enumerate the dictionary if one of the threads writes to the dictionary while the other threads are reading\enumerating through the same dictionary. You may also experience High CPU during this stage. For more details refer to High CPU in .NET app using a static Generic.Dictionary
screenshot1

All threads have a same call stack:
System.Collections.Generic.Dictionary2[[System.__Canon, mscorlib],[System.__Canon, mscorlib]].FindEntry(System.__Canon)+1a6 System.Collections.Generic.Dictionary2[[System.__Canon, mscorlib],[System.__Canon, mscorlib]].TryGetValue(System.__Canon, System.__Canon ByRef)+14
Microsoft.ApplicationInsights.Extensibility.Implementation.LocationContext.get_Ip()+4f
Microsoft.ApplicationInsights.Web.ClientIpHeaderTelemetryInitializer.UpdateRequestTelemetry(System.Web.HttpContext, Microsoft.ApplicationInsights.Extensibility.Implementation.LocationContext)+199
Microsoft.ApplicationInsights.Web.ClientIpHeaderTelemetryInitializer.OnInitializeTelemetry(System.Web.HttpContext, Microsoft.ApplicationInsights.DataContracts.RequestTelemetry, Microsoft.ApplicationInsights.Channel.ITelemetry)+86
Microsoft.ApplicationInsights.Web.Implementation.WebTelemetryInitializerBase.Initialize(Microsoft.ApplicationInsights.Channel.ITelemetry)+86
Microsoft.ApplicationInsights.TelemetryClient.Initialize(Microsoft.ApplicationInsights.Channel.ITelemetry)+26e
Microsoft.ApplicationInsights.TelemetryClient.Track(Microsoft.ApplicationInsights.Channel.ITelemetry)+28
FIE.Common.Web.Code.ApplicationInsights.ApplicationInsightsLogExceptionAttribute.System.ServiceModel.Dispatcher.IErrorHandler.HandleError(System.Exception)+9b
System.ServiceModel.Dispatcher.ErrorBehavior.HandleErrorCommon(System.Exception, System.ServiceModel.Dispatcher.ErrorHandlerFaultInfo ByRef)+a7
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessageCleanup(System.ServiceModel.Dispatcher.MessageRpc ByRef)+307
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage9(System.ServiceModel.Dispatcher.MessageRpc ByRef)+e2
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage8(System.ServiceModel.Dispatcher.MessageRpc ByRef)+ff
System.ServiceModel.Dispatcher.MessageRpc.ProcessError(System.Exception)+2c8
System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean)+169
[[HelperMethodFrame]]
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(System.ServiceModel.Dispatcher.MessageRpc ByRef)+4e3
[[HelperMethodFrame]]
System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(System.ServiceModel.Dispatcher.MessageRpc ByRef)+764
[[HelperMethodFrame]]
screenshot2

@abaranch abaranch added the bug label Apr 25, 2016
@abaranch
Copy link
Contributor

Thank you for reporting the issue. We will investigate to fix.

@abaranch abaranch added this to the 100 milestone Apr 25, 2016
@dnduffy dnduffy self-assigned this Apr 26, 2016
@abaranch
Copy link
Contributor

Fixed. It will be released with 2.1-beta4

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants