MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / clearStaleDaemonLock

Function clearStaleDaemonLock

src/mcp/daemon.ts:642–659  ·  view source on GitHub ↗
(pidPath: string, expectedDeadPid?: number)

Source from the content-addressed store, hash-verified

640 * pid. Returns true when the stale lock is gone (or was already gone).
641 */
642export function clearStaleDaemonLock(pidPath: string, expectedDeadPid?: number): boolean {
643 try {
644 const raw = fs.readFileSync(pidPath, 'utf8');
645 const info = decodeLockInfo(raw);
646 if (info) {
647 // A different pid took over since we read it — not ours to clear.
648 if (expectedDeadPid !== undefined && info.pid !== expectedDeadPid) return false;
649 // Holder is actually alive — never clear a live daemon's lock.
650 if (info.pid > 0 && isProcessAlive(info.pid)) return false;
651 }
652 fs.unlinkSync(pidPath);
653 return true;
654 } catch (err: unknown) {
655 const e = err as NodeJS.ErrnoException;
656 if (e.code === 'ENOENT') return true; // already gone
657 return false;
658 }
659}
660
661/**
662 * Probe whether `pid` is currently alive (signal-0). Treats EPERM as alive on

Callers 1

startDaemonProcessMethod · 0.90

Calls 2

decodeLockInfoFunction · 0.90
isProcessAliveFunction · 0.70

Tested by

no test coverage detected