GitLab.VisualStudio icon indicating copy to clipboard operation
GitLab.VisualStudio copied to clipboard

ThreadPool thread leak in GitLab Extension

Open calvinhsia opened this issue 5 years ago • 1 comments

VS bug #: Bug 1256002: [MemWatson] Memory: Thd_ThreadStack_microsoft_visualstudio_shell_ui_internal!Microsoft.VisualStudio.Services.VsTask.InternalGetResult

Analyzing some user dumps show many threads with the same stack:

For example, 1 dump shows 1800 threads totalling 2 Gigabytes with this same stack:

` # 00 ntdll!NtWaitForMultipleObjects 01 KERNELBASE!WaitForMultipleObjectsEx 02 clr!WaitForMultipleObjectsEx_SO_TOLERANT 03 clr!Thread::DoAppropriateAptStateWait 04 clr!Thread::DoAppropriateWaitWorker 05 clr!Thread::DoAppropriateWait 06 clr!SOIntolerantTransitionHandler::SetNoException 07 clr!CLREventBase::WaitEx 08 clr!CLREventBase::Wait 09 clr!Thread::Wait 0a clr!Thread::Block 0b clr!SyncBlock::Wait 0c clr!ObjHeader::Wait 0d clr!Object::Wait 0e clr!ObjectNative::WaitTimeout 0f mscorlib_ni!System.Threading.Monitor.Wait 10 mscorlib_ni!System.Threading.Monitor.Wait 11 mscorlib_ni!System.Threading.ManualResetEventSlim.Wait 12 mscorlib_ni!System.Threading.Tasks.Task.SpinThenBlockingWait 13 mscorlib_ni!System.Threading.Tasks.Task.InternalWait 14 mscorlib_ni!System.Threading.Tasks.Task.GetResultCore 15 mscorlib_ni!System.Threading.Tasks.Task<System.__Canon>.get_Result 16 Microsoft_VisualStudio_Shell_UI_Internal!Microsoft.VisualStudio.Services.VsTask.InternalGetResult 17 Microsoft_VisualStudio_Shell_UI_Internal!Microsoft.VisualStudio.Services.VsTask.GetResult 18 Microsoft_VisualStudio_Shell_UI_Internal!DomainNeutralILStubClass.IL_STUB_COMtoCLR(IntPtr) 19 clr!COMToCLRDispatchHelper 1a CLRStub[StubLinkStub]@df36169d02f6d060 1b msenv!CThreadAwareServiceProvider::QueryService 1c msenv!CThreadAwareServiceProvider::QueryService 1d Microsoft_VisualStudio_OLE_Interop_ni!DomainBoundILStubClass.IL_STUB_CLRtoCOM(System.Guid ByRef, System.Guid ByRef, IntPtr ByRef)$##6000000 1e Microsoft_VisualStudio_Shell_Framework_ni!Microsoft.VisualStudio.Shell.ServiceProvider.QueryService 1f Microsoft_VisualStudio_Shell_Framework_ni!Microsoft.VisualStudio.Shell.ServiceProvider.QueryService 20 Microsoft_VisualStudio_Shell_Framework_ni!Microsoft.VisualStudio.Shell.ServiceProvider.GetService 21 Microsoft_VisualStudio_Shell_Framework_ni!Microsoft.VisualStudio.Shell.ServiceProvider.GetService 22 Microsoft_VisualStudio_ComponentModelHost_Implementation_ni!Microsoft.VisualStudio.ComponentModelHost.VsComponentModelHostExporter.VsServiceProviderWrapper.GetService 23 GitLab_VisualStudio_Shared!GitLab.VisualStudio.Shared.IServiceProviderExtensions.GetServiceAndCache<GitLab.VisualStudio.Shared.IUIProvider> 24 GitLab_VisualStudio_Shared!GitLab.VisualStudio.Shared.IServiceProviderExtensions.TryGetService 25 GitLab_VisualStudio_Shared!GitLab.VisualStudio.Shared.IServiceProviderExtensions.GetService<Microsoft.VisualStudio.TeamFoundation.Git.Extensibility.IGitExt> 26 GitLab_TeamFoundation_16!GitLab.TeamFoundation.TeamExplorerServices.GetActiveRepository 27 GitLab_TeamFoundation_16!GitLab.TeamFoundation.TeamExplorerServices.IsGitLabRepo 28 GitLab_TeamFoundation_16!GitLab.TeamFoundation.Home.GitLabNavigationItem.<<GitExt_PropertyChanged>b__7_0>d.MoveNext 29 mscorlib_ni!System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start<<<GitExt_PropertyChanged>b__7_0>d> 2a GitLab_TeamFoundation_16!GitLab.TeamFoundation.Home.GitLabNavigationItem.<GitExt_PropertyChanged>b__7_0 2b mscorlib_ni!System.Threading.Tasks.Task<System.Threading.Tasks.Task>.InnerInvoke 2c mscorlib_ni!System.Threading.Tasks.Task.Execute 2d mscorlib_ni!System.Threading.Tasks.Task.ExecutionContextCallback 2e mscorlib_ni!System.Threading.ExecutionContext.RunInternal 2f mscorlib_ni!System.Threading.ExecutionContext.Run 30 mscorlib_ni!System.Threading.Tasks.Task.ExecuteWithThreadLocal 31 mscorlib_ni!System.Threading.Tasks.Task.ExecuteEntry 32 mscorlib_ni!System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem 33 mscorlib_ni!System.Threading.ThreadPoolWorkQueue.Dispatch 34 mscorlib_ni!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback 35 clr!CallDescrWorkerInternal 36 clr!CallDescrWorkerWithHandler 37 clr!MethodDescCallSite::CallTargetWorker 38 clr!MethodDescCallSite::Call_RetBool 39 clr!QueueUserWorkItemManagedCallback 3a clr!ManagedThreadBase_DispatchInner 3b clr!ManagedThreadBase_DispatchMiddle::__l16::Cleanup::{dtor} 3c clr!ManagedThreadBase_DispatchMiddle 3d clr!ManagedThreadBase_DispatchOuter 3e clr!ManagedThreadBase_FullTransitionWithAD 3f clr!ManagedThreadBase::ThreadPool 40 clr!ManagedPerAppDomainTPCount::DispatchWorkItem 41 clr!ThreadpoolMgr::ExecuteWorkRequest 42 clr!ThreadpoolMgr::WorkerThreadStart 43 clr!Thread::intermediateThreadProc 44 kernel32!BaseThreadInitThunk 45 ntdll!__RtlUserThreadStart 46 ntdll!_RtlUserThreadStart

calvinhsia avatar Dec 09 '20 20:12 calvinhsia

Sample ThreadPool Thread Leak demo:

https://github.com/calvinhsia/ThreadPool/blob/master/ThreadPool/MainWindow.xaml.cs

look at the DoDemoThreadLeakAsync method



calvinhsia avatar Dec 11 '20 18:12 calvinhsia