•   Posted in:
  • .NET

Recently I got relatively simple deadlock case, but I found quite interesting things during investigation. Our application hangs when user tries to quit it. I got dump file for this case and started investigation.

Call stack for main thread looks like this:

...
clr!JITutil_MonContention+0x115
System_ni!System.ComponentModel.Component.Dispose(Boolean)$##60031F8+0x40
System_ni!System.IO.FileSystemWatcher.Dispose(Boolean)$##600266D+0xd7
System_ni!System.IO.FileSystemWatcher.Dispose(Boolean)$##600266D+0xa6
System_ni!System.ComponentModel.Component.Dispose()$##60031F7+0x1a
...

As you clearly see, application waiting in FileSystemWatcher’s  System.ComponentModel.Component.Dispose. If you go to https://sourceof.net and paste name of the method there to see source code, you will see that there is lock(this) and it looks like some other thread obtained lock before us. Obviously, I went over other 168 threads and found 2 similar call stacks. First thread was executing event from first