MCPcopy Create free account
hub / github.com/EvoMap/evolver / isStaleProxy

Function isStaleProxy

src/proxy/server/settings.js:65–85  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

63}
64
65function isStaleProxy() {
66 const settings = readSettings();
67 const pid = settings.proxy?.pid;
68 if (!pid) return false;
69 try {
70 // process.kill(pid, 0) probes whether the process exists without sending a
71 // signal. On POSIX it throws ESRCH when the PID is gone. On Windows the
72 // Node.js runtime maps this to the same behavior (ESRCH via uv_kill), so
73 // the cross-platform semantics are consistent. If the current process does
74 // not have permission to query the target PID, EPERM is thrown -- that
75 // means the PID exists and is owned by another user, so we treat it as
76 // live (not stale) rather than crashing.
77 process.kill(pid, 0);
78 return false;
79 } catch (err) {
80 // ESRCH: process does not exist -> stale.
81 // EPERM: process exists but is not ours -> not stale (leave settings alone).
82 if (err.code === 'EPERM') return false;
83 return true;
84 }
85}
86
87function clearIfStale() {
88 if (isStaleProxy()) {

Callers 2

clearIfStaleFunction · 0.85
getProxySettingsFunction · 0.85

Calls 1

readSettingsFunction · 0.85

Tested by

no test coverage detected