How can I debug which thread has an object locked in a .NET Core process on Linux?

Viewed 344

I have a deadlocked .NET Core process running on Linux. I've attached lldb and I can see that there are hundreds of threads stuck on Monitor.ReliableEnter, and they all seem to be trying to lock the same object, but I can't figure out which thread is holding it.

This is trivial on Windows with windbg via the !SyncBlk command, but as far as I can tell, there's no equivalent on Linux. The object's sync block contains the thread that has the lock held, and I can find the sync block index for the object being locked, but I don't know where the sync block table is located in memory.

How can I figure out which thread is holding the lock on this object?

1 Answers

Previously I was unaware of any good way to do this (other than manually disecting the memory using a native debugger + source code for Net Core).

The good news is that we just merged a PR to restore the !SyncBlk functionality. https://github.com/dotnet/coreclr/pull/20830 so I would expect !SyncBlk to be back in the next major .Net Core version. You could also use a daily build from master if you don't want to wait, with the standard caveat that daily builds might have some bugs lurking.

Related