Search code examples
c#multithreadingdeadlockcrash-dumpsfinalizer

Finalizer bloqued hanging the application


Today we received a CrashDump of an application that was hung. Running it thru DebugDiag we got the following information:

Analysis Summary

Error

Description Recommendation

The finalizer thread 5 in this WordHangs.dmp is blocked Review the callstack for the Finalizer thread to see what the finalizer is blocked on. Long running code on a Finalizer thread can increase the number of objects ready for finalization and is bad for the overall memory consumption of the process

Looking at the thread 5 we cannot identify what the thread is doing. The callstack is the following one:

Thread 5 - System ID 13636

Entry point clr!Thread::intermediateThreadProc Create time
19/04/2017 9:32:59 Time spent in user mode 0 Days 00:00:00.093 Time spent in kernel mode 0 Days 00:00:00.078

This thread is not fully resolved and may or may not be a problem. Further analysis of these threads may be required.

.NET Call Stack

[[DebuggerU2MCatchHandlerFrame]]

Full Call Stack

Source

ntdll!NtWaitForSingleObject+15 KERNELBASE!WaitForSingleObjectEx+98 kernel32!WaitForSingleObjectExImplementation+75
clr!CLREventBase::Reset+145 clr!CLREventBase::Reset+18d
clr!CLREventBase::WaitEx+152 clr!CLREventBase::Wait+1a
clr!Thread::WaitSuspendEventsHelper+8a
clr!Thread::WaitSuspendEvents+14
clr!Thread::RareEnablePreemptiveGC+8e
clr!Thread::RareDisablePreemptiveGC+102
clr!WKS::GCHeap::FinalizerThreadWorker+1b5
clr!Thread::DoExtraWorkForFinalizer+1bd
clr!Thread::DoExtraWorkForFinalizer+240
clr!Thread::DoExtraWorkForFinalizer+5f0
[[DebuggerU2MCatchHandlerFrame]]
clr!WKS::GCHeap::FinalizerThreadStart+1a0
clr!Thread::intermediateThreadProc+4d
kernel32!BaseThreadInitThunk+e ntdll!__RtlUserThreadStart+70
ntdll!_RtlUserThreadStart+1b

We have executed Windb with SOSEX loaded to identify any deadlock without success. This is the output generated:

0:000> !dlk Examining SyncBlocks... Scanning for

ReaderWriterLock(Slim) instances... Scanning for holders of

ReaderWriterLock locks... Scanning for holders of ReaderWriterLockSlim

locks... Examining CriticalSections... Scanning for threads waiting on

SyncBlocks... Scanning for threads waiting on ReaderWriterLock

locks... Scanning for threads waiting on ReaderWriterLocksSlim

locks... Scanning for threads waiting on CriticalSections...

*** ERROR: Symbol file could not be found. Defaulted to export symbols for MSO.DLL -

*** ERROR: Symbol file could not be found. Defaulted to export symbols for VSTOLoader.dll -

*** ERROR: Symbol file could not be found. Defaulted to export symbols for WWLIB.DLL -

*** ERROR: Symbol file could not be found. Defaulted to export symbols for WINWORD.EXE -

*** ERROR: Symbol file could not be found. Defaulted to export symbols for Csi.dll -

*** WARNING: Unable to verify checksum for aetpkss1.dll

*** ERROR: Symbol file could not be found. Defaulted to export symbols for aetpkss1.dll -

No deadlocks detected.

Can anyone show us where to look to identify why the finalizer thread was blocked?


Solution

  • In the code we had the following calls:

    GC.Collect();
    GC.WaitForPendingFinalizers();
    GC.Collect();
    GC.WaitForPendingFinalizers();
    

    Since we removed it following this question:

    Is correct to use GC.Collect(); GC.WaitForPendingFinalizers();?

    the issue is gone so I guess somehow this was involved (probably this was not the culprit alone and other code was related as well).