Skip to content

Commit 69769e6

Browse files
authored
fix: Fix the issue of database connections not being released (#11070)
1 parent 2a21f19 commit 69769e6

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

agent/app/service/device_clean.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,11 +647,13 @@ func dropTaskLog(logDir string) {
647647
if err == nil {
648648
_ = xpackDB.Table("tampers").Where("task_id != ?", "").Select("task_id").Find(&usedTasks).Error
649649
}
650+
defer common.CloseDB(xpackDB)
650651
case "System":
651652
xpackDB, err := common.LoadDBConnByPathWithErr(path.Join(global.CONF.Base.InstallDir, "1panel/db/xpack.db"), "xpack.db")
652653
if err == nil {
653654
_ = xpackDB.Model("nodes").Where("task_id != ?", "").Select("task_id").Find(&usedTasks).Error
654655
}
656+
defer common.CloseDB(xpackDB)
655657
default:
656658
dropFileOrDir(logDir)
657659
_ = taskRepo.Delete(repo.WithByType(taskType))

agent/app/service/snapshot_create.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,12 @@ func loadDbConn(snap *snapHelper, targetDir string, req dto.SnapshotCreate) erro
259259
return err
260260
}
261261
} else {
262-
taskDB, err := common.LoadDBConnByPathWithErr(path.Join(targetDir, "db/task.db"), "core.db")
262+
taskDB, err := common.LoadDBConnByPathWithErr(path.Join(targetDir, "db/task.db"), "task.db")
263263
snap.Task.LogWithStatus(i18n.GetWithName("SnapNewDB", "task"), err)
264264
if err != nil {
265265
return err
266266
}
267+
defer common.CloseDB(taskDB)
267268
_ = taskDB.Where("id = ?", req.TaskID).Delete(&model.Task{}).Error
268269
}
269270
if !req.WithOperationLog && global.IsMaster {

0 commit comments

Comments
 (0)