fix(db): 修复 NextID 与写锁重入死锁
CI / Backend (go vet + test) (push) Canceled after 0s
CI / Frontend (lint + build + test) (push) Canceled after 0s

- NextID 改用独立 seqMu,不再依赖数据写锁,杜绝 Lock 内调用 NextID 的死锁
- CaptureAppVolumeForHour 先取 ID 再 Lock
- 新增写锁看门狗:长时间占用时转储 goroutine 栈
- 新增 TestNextIDWhileWriteLocked 回归测试
This commit is contained in:
logan committed 2026-10-31 02:20:34 +08:00
1 parent f1fc7b4a9a
commit 2e97c04f84
3 files changed
+73 -3

No files matched your search

+4 -1
View File
@@ -147,9 +147,12 @@ func CaptureAppVolumeForHour(src *models.LogSource, hour time.Time) error {
if db == nil {
return fmt.Errorf("数据库未初始化")
}
// NextID 内部会自己加锁;必须在 db.Lock() 之前调用。
// JsonDB 的 mutex 不可重入,先 Lock 再 NextID 会永久死锁并占住写锁,
// 导致所有读库接口(登录、列表)全部卡死。
nextID := db.NextID("appVolumeSnapshots")
db.Lock()
defer db.Unlock()
nextID := db.NextID("appVolumeSnapshots")
for _, r := range rows {
// 幂等:同 (hour, source, ns, app) 已存在则更新,不重复插入
found := false