deadlock
Use uprobe to trace pthread_mutex_lock and pthread_mutex_unlock in libc.so and detect potential deadlocks.
Getting started
Running the gadget:
- kubectl gadget
- ig
$ kubectl gadget run ghcr.io/inspektor-gadget/gadget/deadlock:latest [flags]
$ sudo ig run ghcr.io/inspektor-gadget/gadget/deadlock:latest [flags]
Flags
--pid
Show only events generated by processes with this pid
Default value: ""
Guide
To generate mutex lock/unlock events, you can run a test
program in another container.
For this example, we use a test C++ program (from BCC) with lock inversions that can cause a potential deadlock.
The deadlock gadget traces all potential deadlocks:
$ sudo ig run ghcr.io/inspektor-gadget/gadget/deadlock:latest
RUNTIME.CONTAINERNAME PID NODES STACK_IDS COMM
hungry_montalcini 39046 3 [77, 13], [149, 42], [11, 109] test
hungry_montalcini 39046 4 [51, 208], [87, 52], [239, 71], [175, 35] test
Notes
- This gadget detects "potential" deadlocks and not just actual deadlocks as a deadlock that didn't happen during the trace could happen in the future. A deadlock occurring depends on various factors such as thread scheduling and order of mutex acquisitions/releases, and hence it makes sense to report mutex lock order inversions as potentially unsafe resource management.
- Tracing with
--host
will slow down the gadget due to too many events.