Thread leak in JustMock
I am a member of the Visual Studio Perf Reliability team
Recently, I’ve found several customer dumps with huge # of threads.
In this dump:
Watson : Cab Search (microsoft.com)
Thd_ThreadStack_telerik_justmock_debugwindow_service_client!Telerik.JustMock.DebugWindow.Service.Client.ConnectionSetupServiceClientBase`[[System.__Canon,mscorlib]].get_ServiceAvailable
2,136,997,888
Progress® Telerik® JustMock Feedback Portal
There are 2084 threads using 2G mem, most with the stack below:
This is caused by threadpool starvation: the JustMock call ties up a thread for more than 1 second, then another request comes in.
The CLR will create an additional thread after 1 second to satisfy the request. This keeps happening and creates thousands of threads, each with size 1Meg.
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!AwareLock::EnterEpilogHelper
0a clr!ThreadDebugBlockingInfo::PopBlockingItem
0b clr!DebugBlockingItemHolder::{dtor}
0c clr!AwareLock::EnterEpilog
0d clr!AwareLock::Enter
0e clr!AwareLock::Contention
0f clr!JITutil_MonReliableContention
10 Telerik_JustMock_DebugWindow_Service_Client!Telerik.JustMock.DebugWindow.Service.Client.ConnectionSetupServiceClientBase<Telerik.JustMock.DebugWindow.Service.Proxy.TraceEventsSubscriptionServiceProxy>.get_ServiceAvailable
11 Telerik_JustMock_DebugWindow_Service_Client!Telerik.JustMock.DebugWindow.Service.Client.SessionServiceClientBase<Telerik.JustMock.DebugWindow.Service.Proxy.MockRepositorySubscriptionServiceProxy>.KeepAliveTimer_Elapsed
12 System_ni!System.Timers.Timer.MyTimerCallback
13 mscorlib_ni!System.Threading.TimerQueueTimer.CallCallbackInContext
14 mscorlib_ni!System.Threading.ExecutionContext.RunInternal
15 mscorlib_ni!System.Threading.ExecutionContext.Run
16 mscorlib_ni!System.Threading.TimerQueueTimer.CallCallback
17 mscorlib_ni!System.Threading.TimerQueueTimer.Fire
18 mscorlib_ni!System.Threading.TimerQueue.FireNextTimers
19 mscorlib_ni!System.Threading.TimerQueue.AppDomainTimerCallback
1a clr!CallDescrWorkerInternal
1b clr!CallDescrWorkerWithHandler
1c clr!MethodDescCallSite::CallTargetWorker
1d clr!MethodDescCallSite::Call
1e clr!AppDomainTimerCallback_Worker
1f clr!ManagedThreadBase_DispatchInner
20 clr!ManagedThreadBase_DispatchMiddle::__l16::Cleanup::{dtor}
21 clr!ManagedThreadBase_DispatchMiddle
22 clr!ManagedThreadBase_DispatchOuter
23 clr!ManagedThreadBase_FullTransitionWithAD
24 clr!ManagedThreadBase::ThreadPool
25 clr!AppDomainTimerCallback
26 clr!ThreadpoolMgr::AsyncTimerCallbackCompletion
27 clr!UnManagedPerAppDomainTPCount::DispatchWorkItem
28 clr!ThreadpoolMgr::ExecuteWorkRequest
29 clr!ThreadpoolMgr::WorkerThreadStart
2a clr!Thread::intermediateThreadProc
2b kernel32!BaseThreadInitThunk
2c ntdll!__RtlUserThreadStart
2d ntdll!_RtlUserThreadStart