fix(stability): cancel-install 增加 SIGTERM→SIGKILL 超时降级防止僵尸进程

- install-manager.ts: cancel-install 仅 kill()(SIGTERM),子进程忽略时成僵尸;新增 forceKill 封装先 SIGTERM 后 5s 超时降级 SIGKILL
- PR 审查其余 6 项经代码实证均为误报/可维护性建议,未改动:JSON.parse 已有 try-catch、pkgname 已 PKGNAME_PATTERN 校验防穿越、shell-caller 已双引号+白名单、watch 不修改 apps.length 无循环、baseApps 量级无需 shallowRef、install-complete 已 off 清理
This commit is contained in:
xiyidaiwa
2026-08-13 22:49:36 +08:00
parent cdd94c650d
commit e67f4752a4
2 changed files with 17 additions and 4 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
spark-store (5.2.1.6-test) UNRELEASED; urgency=medium
spark-store (5.2.1.7-test) UNRELEASED; urgency=medium
* Initial release. (Closes: #nnnn) <nnnn is the bug number of your ITP>
+16 -3
View File
@@ -629,9 +629,22 @@ ipcMain.on("cancel-install", (event, id) => {
const isRunning = task.phase === "downloading" || task.phase === "installing";
if (isRunning) {
// 运行中的任务:终止进程,由对应的阶段处理器在 finally 中清理计数器与队列
task.download_process?.kill();
task.install_process?.kill();
// 运行中的任务:先发 SIGTERM 优雅终止;若 5s 内未退出,降级 SIGKILL 强制杀除,
// 避免子进程忽略 SIGTERM 变成僵尸进程(改进项:进程取消需 SIGKILL 降级处理)。
const forceKill = (proc: ChildProcess | null, label: string) => {
if (!proc || proc.killed) return;
proc.kill("SIGTERM");
const pid = proc.pid;
setTimeout(() => {
if (proc && !proc.killed) {
logger.warn(`任务 ${id}${label} 进程(${pid}) 未响应 SIGTERM,发送 SIGKILL`);
proc.kill("SIGKILL");
}
}, 5000);
};
forceKill(task.download_process, "下载");
forceKill(task.install_process, "安装");
// 由对应的阶段处理器在 finally 中清理计数器与队列
} else {
// 排队中的任务(未开始执行):直接清理并调度
tasks.delete(id);