Ways to debug holding locks bug in runtime

72 views
Skip to first unread message

Qingwei Li

unread,
Mar 21, 2026, 9:32:47 AM (2 days ago) Mar 21
to golang-nuts
I'm currently adding an mechanism which changes `mp.locks` to avoid G to be preempted in go 1.24.2. Is there a good way to debug "schedule: holding locks" and "stopTheWorld: holding locks" bugs? I want to know the dynamic changing process of `mp.locks` to debug my new mechanism.

Currently I use `mp.lockReason int32` and `mp.lastlocks int32` to track some changes of `mp.locks`. But there are so many points in runtime to call `acquirem`/`releasem` which increases/decreases `mp.locks`. The naive way is to add a constant for each point. Although it may work, it's boring somehow. Is there some other ways that I can track the `mp.locks` changing process?

Besides, single int32 is not enough for tracking a process. So I will also try array of int32 as a queue with limited size.

Are there other better ways? Any suggestions would be greatly appreciated.

note: `throw` in `acquirem`/`releasem` does not print the stacktrace and will lead to segmentation fault(I don't know the reason). So it's not feasible to add something in `acquirem`/`releasem`.

Thanks!
Reply all
Reply to author
Forward
0 new messages