fix: Fix the issue of database connections not being released (#11070)

This commit is contained in:
ssongliu
2025-11-25 10:07:19 +00:00
committed by GitHub
parent 2a21f194d3
commit 69769e6203
2 changed files with 4 additions and 1 deletions
+2
View File
@@ -647,11 +647,13 @@ func dropTaskLog(logDir string) {
if err == nil {
_ = xpackDB.Table("tampers").Where("task_id != ?", "").Select("task_id").Find(&usedTasks).Error
}
defer common.CloseDB(xpackDB)
case "System":
xpackDB, err := common.LoadDBConnByPathWithErr(path.Join(global.CONF.Base.InstallDir, "1panel/db/xpack.db"), "xpack.db")
if err == nil {
_ = xpackDB.Model("nodes").Where("task_id != ?", "").Select("task_id").Find(&usedTasks).Error
}
defer common.CloseDB(xpackDB)
default:
dropFileOrDir(logDir)
_ = taskRepo.Delete(repo.WithByType(taskType))
+2 -1
View File
@@ -259,11 +259,12 @@ func loadDbConn(snap *snapHelper, targetDir string, req dto.SnapshotCreate) erro
return err
}
} else {
taskDB, err := common.LoadDBConnByPathWithErr(path.Join(targetDir, "db/task.db"), "core.db")
taskDB, err := common.LoadDBConnByPathWithErr(path.Join(targetDir, "db/task.db"), "task.db")
snap.Task.LogWithStatus(i18n.GetWithName("SnapNewDB", "task"), err)
if err != nil {
return err
}
defer common.CloseDB(taskDB)
_ = taskDB.Where("id = ?", req.TaskID).Delete(&model.Task{}).Error
}
if !req.WithOperationLog && global.IsMaster {