在服务应用程序中调用GC.WaitForPendingFinalizers()时查找死锁

时间:2014-03-12 19:10:53

标签: .net multithreading .net-4.0 windows-services garbage-collection

我有一个我的应用程序的进程转储,其中一个线程调用了GC.WaitForPendingFinalizers()并且不再返回。

[ 在出现关于WaitForPendingFinalizers 的使用的任何讨论之前:对不起但是必须这样做。虽然我在与EntityFramework相关的所有内容上使用“using()”和“try finally dispose”:SQLite(1.0.90)在使用GC.Collect()和GC的组合时最终只删除-shm和-wal锁定文件处理完上下文后,.WaitForPendingFinalizers()。 ]

死锁代码在同一台计算机上运行时从GUI(WPF)或控制台应用程序使用时没有问题 - 我还尝试了几个不同的用户帐户(本地服务,网络服务,系统,本地具有管理员权限的用户)但总是一样的:它总是在对GC.WaitForPendingFinalizers()的完全相同的调用上死锁 - 我可以在每次尝试时在该机器上重现这个,并且在任何其他机器上都不能。

该机器使用的是Windows 7 Enterprise 64位 - 16核/ 48 GB RAM。只有一个线程正在调用WaitForPendingFinalizers。

所以我发现等待WaitForPendingFinalizers返回的线程,但我看不到任何正在执行任何终结器代码的线程 - 我自己的代码中几乎没有。

所有线程的完全调用(任何人都可以发现死锁吗?)

Main Thread Main Thread sechost.dll!000007fefd15affb
        ntdll.dll!NtWaitForSingleObject()
        KERNELBASE.dll!WaitForSingleObjectEx()
        sechost.dll!ScSendResponseReceiveControls(void *,void *,unsigned long,unsigned long,unsigned __int64,unsigned long,unsigned long *,unsigned short * *,struct _SC_CONTROL_MESSAGE_OUT_PARAMS *)
        sechost.dll!ScDispatcherLoop(void * *)
        sechost.dll!StartServiceCtrlDispatcherW()
        [Managed to Native Transition]
        System.ServiceProcess.dll!System.ServiceProcess.ServiceBase.Run(System.ServiceProcess.ServiceBase[] services)
        MyCompany.Common.ServiceHelper.dll!MyCompany.Common.ServiceHelper.ServiceCore.DoRunNtServices()
        MyCompany.Common.ServiceHelper.dll!MyCompany.Common.ServiceHelper.ServiceCore.InternalStart<MyCompanyInstaller.ServiceInstallHelper>(MyCompany.Common.IVersionHolderWithAppName nameProvider, System.Collections.Generic.IList<string> args, MyCompany.Common.ServiceHelper.ServiceCore.ConsoleRunInit consoleRunInit)
        MyCompany.Common.ServiceHelper.dll!MyCompany.Common.ServiceHelper.ServiceCore.Start<MyCompanyInstaller.ServiceInstallHelper>(MyCompany.Common.IVersionHolderWithAppName nameProvider, string[] args, MyCompany.Common.ServiceHelper.ServiceCore.ConsoleRunInit consoleRunInit)
        ServiceApp.exe!MyCompany.MyApp.ServiceApp.Program.DoRun(string[] args = {string[0]}) Line 225
        ServiceApp.exe!MyCompany.MyApp.ServiceApp.Program.Main(string[] args = {string[0]}) Line 149
        [Native to Managed Transition]
        mscoreei.dll!_CorExeMain()
        mscoree.dll!_CorExeMain_Exported()
        kernel32.dll!BaseThreadInitThunk()
        ntdll.dll!RtlUserThreadStart()

Worker Thread   clr.dll thread  ntdll.dll!NtWaitForMultipleObjects
        ntdll.dll!NtWaitForMultipleObjects()
        KERNELBASE.dll!WaitForMultipleObjectsEx()
        kernel32.dll!WaitForMultipleObjectsExImplementation()
        kernel32.dll!BaseThreadInitThunk()
        ntdll.dll!RtlUserThreadStart()

Worker Thread   clr.dll thread  ole32.dll!000007fefcf7e68e
        ntdll.dll!NtWaitForSingleObject()
        KERNELBASE.dll!WaitForSingleObjectEx()
        ole32.dll!GetToSTA(OXIDEntry * pOXIDEntry=0x000000000037f680, CMessageCall * pCall=0x0000000019be3ad0) Line 131
        ole32.dll!CRpcChannelBuffer::SwitchAptAndDispatchCall(CMessageCall * * ppCall=0x00000000ffffffff) Line 4413
        ole32.dll!CRpcChannelBuffer::SendReceive2(tagRPCOLEMESSAGE * pMessage=0x00003e104e223606, unsigned long * pstatus=0x0000000000000000) Line 4074
        ole32.dll!CAptRpcChnl::SendReceive(tagRPCOLEMESSAGE * pMsg=0x0000000000000008, unsigned long * pulStatus=0x0000000019b697b0) Line 603
        ole32.dll!CCtxComChnl::SendReceive(tagRPCOLEMESSAGE * pMessage=0x000007fe00000000, unsigned long * pulStatus=0x0000000000000000) Line 679
        ole32.dll!NdrExtpProxySendReceive(void * pThis=0x000000000116ed70, _MIDL_STUB_MESSAGE * pStubMsg=0x0000000019c311d8) Line 1932
        rpcrt4.dll!000007fefd72b949()
        ole32.dll!ObjectStublessClient(void * ParamAddress=0x0000000000379a00, __int64 * FloatRegisters=0x000000000037f680, long Method=432606984) Line 621
        ole32.dll!ObjectStubless() Line 117
        ole32.dll!CObjectContext::InternalContextCallback(HRESULT (void *) * pfnCallback=0x000000001ad40090, void * pParam=0x000000000037f680, const _GUID & riid={...}, int iMethod=2, IUnknown * pUnk=0x0000000000000000)
        ole32.dll!CObjectContext::ContextCallback(HRESULT (tagComCallData *) * pfnCallback=0x000000000116f378, tagComCallData * pParam=0x000000000116f328, const _GUID & riid={...}, int iMethod=2, IUnknown * pUnk=0x0000000000000000) Line 4182
        kernel32.dll!BaseThreadInitThunk()
        ntdll.dll!RtlUserThreadStart()

Worker Thread   ntdll.dll!TppWaiterpThread()    ntdll.dll!NtWaitForMultipleObjects
        ntdll.dll!NtWaitForMultipleObjects()
        ntdll.dll!TppWaiterpThread()
        kernel32.dll!BaseThreadInitThunk()
        ntdll.dll!RtlUserThreadStart()

Worker Thread   ole32.dll thread    ole32.dll!000007fefcf501d0
        ntdll.dll!ZwDelayExecution()
        KERNELBASE.dll!SleepEx()
        ole32.dll!CROIDTable::WorkerThreadLoop(void * param=0x0000000019b78f20) Line 1345
        ole32.dll!CRpcThread::WorkerLoop() Line 257
        ole32.dll!CRpcThreadCache::RpcWorkerThreadEntry(void * param=0x0000000000000000) Line 63
        kernel32.dll!BaseThreadInitThunk()
        ntdll.dll!RtlUserThreadStart()

Worker Thread   ntdll.dll!TppWorkerThread() ntdll.dll!NtWaitForWorkViaWorkerFactory
        ntdll.dll!NtWaitForWorkViaWorkerFactory()
        ntdll.dll!TppWorkerThread()
        kernel32.dll!BaseThreadInitThunk()
        ntdll.dll!RtlUserThreadStart()

Worker Thread   clr.dll thread  System.Management.dll!System.Management.MTAHelper.WorkerThread
        ntdll.dll!NtWaitForMultipleObjects()
        KERNELBASE.dll!WaitForMultipleObjectsEx()
        kernel32.dll!WaitForMultipleObjectsExImplementation()
        [Managed to Native Transition]
        mscorlib.dll!System.Threading.WaitHandle.InternalWaitOne(System.Runtime.InteropServices.SafeHandle waitableSafeHandle, long millisecondsTimeout, bool hasThreadAffinity, bool exitContext) Line 241
        System.Management.dll!System.Management.MTAHelper.WorkerThread() Line 2044
        mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 581
        mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 530
        mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 519
        mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() Line 109
        [Native to Managed Transition]
        kernel32.dll!BaseThreadInitThunk()
        ntdll.dll!RtlUserThreadStart()

Worker Thread   clr.dll thread  MyCompany.Common.JobDirectory.dll!MyCompany.Common.JobDirectory.JobDirectoryWatchingServiceBase<MyCompany.MyApp.CS.JobWorker,MyCompany.MyApp.CS.MainJobType,MyCompany.MyApp.CS.JobDirectoryManager>.Run
        ntdll.dll!NtWaitForMultipleObjects()
        KERNELBASE.dll!WaitForMultipleObjectsEx()
        kernel32.dll!WaitForMultipleObjectsExImplementation()
        [Managed to Native Transition]
        mscorlib.dll!System.Threading.ManualResetEventSlim.Wait(int millisecondsTimeout = 60000, System.Threading.CancellationToken cancellationToken) Line 669
        mscorlib.dll!System.Threading.ManualResetEventSlim.Wait(System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken) Line 503
        MyCompany.Common.JobDirectory.dll!MyCompany.Common.JobDirectory.JobDirectoryWatchingServiceBase<MyCompany.MyApp.CS.JobWorker,MyCompany.MyApp.CS.MainJobType,MyCompany.MyApp.CS.JobDirectoryManager>.Run(System.Threading.CancellationToken cancellationToken)
        MyCompany.Common.ServiceHelper.dll!MyCompany.Common.ServiceHelper.ServiceWorkerBase.TaskRunner.RunMethod()
        mscorlib.dll!System.Threading.Tasks.Task.Execute() Line 2459
        mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 581
        mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 530
        mscorlib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot = Id = 3, Status = Running, Method = The runtime has refused to evaluate the expression at this time.) Line 2785
        mscorlib.dll!System.Threading.Tasks.Task.ExecuteEntry(bool bPreventDoubleExecution) Line 2728
        mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 581
        mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 530
        mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 519
        mscorlib.dll!System.Threading.ThreadHelper.ThreadStart(object obj) Line 87
        [Native to Managed Transition]
        kernel32.dll!BaseThreadInitThunk()
        ntdll.dll!RtlUserThreadStart()

Worker Thread   clr.dll thread  ServiceApp.exe!MyCompany.MyApp.ServiceApp.ComparisonRunnerService.ProcessDbUpdateJob
        ntdll.dll!NtWaitForMultipleObjects()
        KERNELBASE.dll!WaitForMultipleObjectsEx()
        kernel32.dll!WaitForMultipleObjectsExImplementation()
        [Managed to Native Transition]
        mscorlib.dll!System.GC.WaitForPendingFinalizers() Line 320
        ServiceApp.exe!MyCompany.MyApp.ServiceApp.ComparisonRunnerService.ProcessDbUpdateJob(MyCompany.MyApp.CS.JobWorker job = {MyCompany.MyApp.CS.JobWorker}, MyCompany.Common.ServiceHelper.IJobCommunicator jobCommunicator = {MyCompany.Common.JobDirectory.JobDirectoryWatchingServiceBase<MyCompany.MyApp.CS.JobWorker,MyCompany.MyApp.CS.MainJobType,MyCompany.MyApp.CS.JobDirectoryManager>.JobCommunicatorWithJob}) Line 280
        ServiceApp.exe!MyCompany.MyApp.ServiceApp.ComparisonRunnerService.DoProcessJob(MyCompany.MyApp.CS.JobWorker job = {MyCompany.MyApp.CS.JobWorker}, MyCompany.Common.ServiceHelper.IJobCommunicator jobCommunicator = {MyCompany.Common.JobDirectory.JobDirectoryWatchingServiceBase<MyCompany.MyApp.CS.JobWorker,MyCompany.MyApp.CS.MainJobType,MyCompany.MyApp.CS.JobDirectoryManager>.JobCommunicatorWithJob}) Line 106
        ServiceApp.exe!MyCompany.MyApp.ServiceApp.JobDirectoryWatchingServiceBase.ProcessJob(MyCompany.MyApp.CS.JobWorker job = {MyCompany.MyApp.CS.JobWorker}, MyCompany.Common.ServiceHelper.IJobCommunicator jobCommunicator = {MyCompany.Common.JobDirectory.JobDirectoryWatchingServiceBase<MyCompany.MyApp.CS.JobWorker,MyCompany.MyApp.CS.MainJobType,MyCompany.MyApp.CS.JobDirectoryManager>.JobCommunicatorWithJob}) Line 56
        MyCompany.Common.JobDirectory.dll!MyCompany.Common.JobDirectory.JobDirectoryWatchingServiceBase<MyCompany.MyApp.CS.JobWorker,MyCompany.MyApp.CS.MainJobType,MyCompany.MyApp.CS.JobDirectoryManager>.Run(System.Threading.CancellationToken cancellationToken)
        MyCompany.Common.ServiceHelper.dll!MyCompany.Common.ServiceHelper.ServiceWorkerBase.TaskRunner.RunMethod()
        mscorlib.dll!System.Threading.Tasks.Task.Execute() Line 2459
        mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 581
        mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 530
        mscorlib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot = Id = 2, Status = Running, Method = The runtime has refused to evaluate the expression at this time.) Line 2785
        mscorlib.dll!System.Threading.Tasks.Task.ExecuteEntry(bool bPreventDoubleExecution) Line 2728
        mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 581
        mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 530
        mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 519
        mscorlib.dll!System.Threading.ThreadHelper.ThreadStart(object obj) Line 87
        [Native to Managed Transition]
        kernel32.dll!BaseThreadInitThunk()
        ntdll.dll!RtlUserThreadStart()

Worker Thread   clr.dll thread  MyCompany.Common.JobDirectory.dll!MyCompany.Common.JobDirectory.JobDirectoryWatchingServiceBase<MyCompany.MyApp.CS.JobWorker,MyCompany.MyApp.CS.MainJobType,MyCompany.MyApp.CS.JobDirectoryManager>.Run
        ntdll.dll!NtWaitForMultipleObjects()
        KERNELBASE.dll!WaitForMultipleObjectsEx()
        kernel32.dll!WaitForMultipleObjectsExImplementation()
        [Managed to Native Transition]
        mscorlib.dll!System.Threading.ManualResetEventSlim.Wait(int millisecondsTimeout = 60000, System.Threading.CancellationToken cancellationToken) Line 669
        mscorlib.dll!System.Threading.ManualResetEventSlim.Wait(System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken) Line 503
        MyCompany.Common.JobDirectory.dll!MyCompany.Common.JobDirectory.JobDirectoryWatchingServiceBase<MyCompany.MyApp.CS.JobWorker,MyCompany.MyApp.CS.MainJobType,MyCompany.MyApp.CS.JobDirectoryManager>.Run(System.Threading.CancellationToken cancellationToken)
        MyCompany.Common.ServiceHelper.dll!MyCompany.Common.ServiceHelper.ServiceWorkerBase.TaskRunner.RunMethod()
        mscorlib.dll!System.Threading.Tasks.Task.Execute() Line 2459
        mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 581
        mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 530
        mscorlib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot = Id = 4, Status = Running, Method = The runtime has refused to evaluate the expression at this time.) Line 2785
        mscorlib.dll!System.Threading.Tasks.Task.ExecuteEntry(bool bPreventDoubleExecution) Line 2728
        mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 581
        mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 530
        mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 519
        mscorlib.dll!System.Threading.ThreadHelper.ThreadStart(object obj) Line 87
        [Native to Managed Transition]
        kernel32.dll!BaseThreadInitThunk()
        ntdll.dll!RtlUserThreadStart()

Worker Thread   clr.dll thread  ntdll.dll!NtRemoveIoCompletion
        ntdll.dll!NtRemoveIoCompletion()
        KERNELBASE.dll!GetQueuedCompletionStatus()
        kernel32.dll!GetQueuedCompletionStatusStub()
        kernel32.dll!BaseThreadInitThunk()
        ntdll.dll!RtlUserThreadStart()

Worker Thread   ntdll.dll!TppWorkerThread() ntdll.dll!NtWaitForWorkViaWorkerFactory
        ntdll.dll!NtWaitForWorkViaWorkerFactory()
        ntdll.dll!TppWorkerThread()
        kernel32.dll!BaseThreadInitThunk()
        ntdll.dll!RtlUserThreadStart()

0 个答案:

没有答案