debug: 死锁监控+DebugMutex+ChSend+GoStart 调试工具

This commit is contained in:
2026-06-28 13:01:54 +08:00
parent 537e4ed550
commit dc410c1cff
2 changed files with 123 additions and 0 deletions
@@ -596,6 +596,8 @@ func (t *Thinker) Start() {
if t.lightThinkEnabled && t.lightThinkInterval > 0 {
t.wg.Add(1)
go t.lightThinkLoop()
// 死锁监控:每30秒检测 t.mu 是否正常
t.StartDeadlockMonitor()
}
// 启动平台静默观察循环
@@ -2670,3 +2672,26 @@ func (t *Thinker) DeadlockDetected(timeout time.Duration) bool {
func (t *Thinker) LockHolder() (string, time.Time) {
return t.muLockedBy, t.muLockedAt
}
// StartDeadlockMonitor 启动死锁监控:定期检查 t.mu 是否有 orphaned lock
func (t *Thinker) StartDeadlockMonitor() {
go func() {
ticker := time.NewTicker(30 * time.Second)
defer ticker.Stop()
for range ticker.C {
done := make(chan struct{})
go func() {
t.muLock()
t.muUnlock()
close(done)
}()
select {
case <-done:
// lock is healthy
case <-time.After(15 * time.Second):
log.Printf("[deadlock-monitor] ⚠️ t.mu 超过15秒无法获取!可能死锁。锁持有者: %s, 持有时长: %v",
t.muLockedBy, time.Since(t.muLockedAt).Round(time.Second))
}
}
}()
}