fix(mitm): recover from stale lock file on server start
Detect dead PID in lock file and reclaim it instead of failing, and drop unused fs dependency. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
1885ad7f64
commit
da0149de97
2 changed files with 9 additions and 4 deletions
|
|
@ -24,7 +24,6 @@
|
||||||
"bcryptjs": "^3.0.3",
|
"bcryptjs": "^3.0.3",
|
||||||
"confbox": "^0.2.4",
|
"confbox": "^0.2.4",
|
||||||
"express": "^5.2.1",
|
"express": "^5.2.1",
|
||||||
"fs": "^0.0.1-security",
|
|
||||||
"http-proxy-middleware": "^3.0.5",
|
"http-proxy-middleware": "^3.0.5",
|
||||||
"jose": "^6.1.3",
|
"jose": "^6.1.3",
|
||||||
"marked": "^18.0.1",
|
"marked": "^18.0.1",
|
||||||
|
|
|
||||||
|
|
@ -496,9 +496,15 @@ async function startServer(apiKey, sudoPassword, forceKillPort443 = false) {
|
||||||
fs.writeFileSync(LOCK_FILE, String(process.pid), { flag: "wx" });
|
fs.writeFileSync(LOCK_FILE, String(process.pid), { flag: "wx" });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.code === "EEXIST") {
|
if (e.code === "EEXIST") {
|
||||||
throw new Error("MITM server is already starting (lock contention)");
|
let stale = false;
|
||||||
}
|
try {
|
||||||
throw e;
|
const pid = parseInt(fs.readFileSync(LOCK_FILE, "utf-8").trim(), 10);
|
||||||
|
stale = !pid || !isProcessAlive(pid);
|
||||||
|
} catch { stale = true; } // unreadable lock → treat as stale
|
||||||
|
if (!stale) throw new Error("MITM server is already starting (lock contention)");
|
||||||
|
try { fs.unlinkSync(LOCK_FILE); } catch { /* ignore */ }
|
||||||
|
fs.writeFileSync(LOCK_FILE, String(process.pid), { flag: "wx" });
|
||||||
|
} else throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue