AI Engineering Practice

Diagnose a Deadlock or Lock Contention Issue From a Thread Dump

I have a thread (or goroutine) dump from a process that's either hung entirely or running far slower than expected. I suspect lock contention or a deadlock, but I want a systematic read of the dump rather than eyeballing it for something that looks scary.

Here's the dump:

[PASTE THREAD/GOROUTINE DUMP]

Context:
- Runtime/language: [e.g. JVM, Go, Python with GIL, .NET]
- Symptom: [DESCRIBE — e.g. fully hung and unresponsive, or degraded throughput under load, or intermittent stalls]
- What changed recently, if anything: [DESCRIBE — new lock added, new concurrent code path, increased traffic, new dependency version]

Help me work through this systematically:
1. Identify any true circular wait (thread A holds lock 1 and wants lock 2, thread B holds lock 2 and wants lock 1) versus threads that are merely slow to acquire a lock because one holder is doing a lot of work while holding it — these need completely different fixes.
2. Name the specific lock(s) or monitor(s) involved by whatever identifier the dump gives you, and map each to the code path most likely to be acquiring it, based on the stack frames shown.
3. Point out if a large number of threads are blocked on the same lock, which usually means a hot lock that's too coarse-grained rather than an actual deadlock — flag this distinctly since the fix is narrowing the critical section or switching data structures, not breaking a cycle.
4. Flag anything suspicious about lock ordering across the stacks shown (the same two locks acquired in different orders in different threads) even if this particular dump doesn't show an active deadlock — that's a latent bug that will eventually fire.
5. Tell me what additional evidence I should capture next time if this dump doesn't fully explain the symptom (e.g. a second dump a few seconds later to see if threads are moving, or the state of the locks in question rather than just the threads).

Give me a ranked list of the most likely root causes given the evidence in the dump, not just a description of what each thread is doing.

Sign in to upvote this prompt.