mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 08:50:22 +08:00
fix: 回收流程防 PID 复用误杀并等待端口释放,版本 1.1.86(#197/#198)
合并 #197/#198 后加固:记录 pid 命令行不可读时必须在监听端口上才杀;杀不掉保留记录下次重试;taskkill 后等待进程退出再绑端口。桌面换包顺序与失败兜底随 PR #198 一并发布。
This commit is contained in:
1 parent
52d3b2a2f2
commit
1bdf239970
5 files changed
+117
-14
No files matched your search
@@ -11,6 +11,7 @@ import {
|
||||
parseNetstatListeners,
|
||||
readRecord,
|
||||
recordPath,
|
||||
waitGone,
|
||||
writeRecord,
|
||||
} from "../lib/web-reclaim.js";
|
||||
|
||||
@@ -82,3 +83,18 @@ test("parseLsofPids 处理多行/空输出", () => {
|
||||
assert.deepEqual(parseLsofPids(""), []);
|
||||
assert.deepEqual(parseLsofPids(" \n"), []);
|
||||
});
|
||||
|
||||
test("waitGone 对空列表/已退出 pid 立即返回", () => {
|
||||
const t0 = Date.now();
|
||||
waitGone([]);
|
||||
waitGone([0, -1, 999999]);
|
||||
assert.ok(Date.now() - t0 < 1000, "不应为已退出的进程等到超时");
|
||||
});
|
||||
|
||||
test("preflight 侧车:记录 pid 只有仍在监听端口时才允许盲杀", () => {
|
||||
const side = fs.readFileSync(new URL("../lib/web-preflight-entry.js", import.meta.url), "utf8");
|
||||
assert.match(side, /const ownsPort = listeners\.includes\(recPid\)/);
|
||||
assert.match(side, /isDshWeb\(cmd\) \|\| \(!cmd && ownsPort\)/);
|
||||
assert.match(side, /if \(rec && !recStillAlive\)/);
|
||||
assert.match(side, /waitGone\(killedPids\)/);
|
||||
});
|
||||
Reference in new issue
Block a user