mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-09-20 21:50:11 +08:00
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:
Vendored
+1
-1
@@ -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>
|
* Initial release. (Closes: #nnnn) <nnnn is the bug number of your ITP>
|
||||||
|
|
||||||
|
|||||||
@@ -629,9 +629,22 @@ ipcMain.on("cancel-install", (event, id) => {
|
|||||||
const isRunning = task.phase === "downloading" || task.phase === "installing";
|
const isRunning = task.phase === "downloading" || task.phase === "installing";
|
||||||
|
|
||||||
if (isRunning) {
|
if (isRunning) {
|
||||||
// 运行中的任务:终止进程,由对应的阶段处理器在 finally 中清理计数器与队列
|
// 运行中的任务:先发 SIGTERM 优雅终止;若 5s 内未退出,降级 SIGKILL 强制杀除,
|
||||||
task.download_process?.kill();
|
// 避免子进程忽略 SIGTERM 变成僵尸进程(改进项:进程取消需 SIGKILL 降级处理)。
|
||||||
task.install_process?.kill();
|
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 {
|
} else {
|
||||||
// 排队中的任务(未开始执行):直接清理并调度
|
// 排队中的任务(未开始执行):直接清理并调度
|
||||||
tasks.delete(id);
|
tasks.delete(id);
|
||||||
|
|||||||
Reference in New Issue
Block a user