fix: prevent self-killing pidfile race condition
- Changed acquirePidfile() to only warn when another instance is detected - No longer kills existing processes, just logs warning and continues - Prevents continuous restart loop when bot detects itself running - Maintains all Ruflo-inspired features (plugins, hooks, swarm, memory) - All 18 tools, 6 skills, 9 agents, 6 swarm tools still loaded
This commit is contained in:
@@ -38,17 +38,15 @@ function acquirePidfile() {
|
|||||||
const oldPid = parseInt(fs.readFileSync(PIDFILE, 'utf8').trim());
|
const oldPid = parseInt(fs.readFileSync(PIDFILE, 'utf8').trim());
|
||||||
// Check if old process is still alive
|
// Check if old process is still alive
|
||||||
try { process.kill(oldPid, 0);
|
try { process.kill(oldPid, 0);
|
||||||
logger.warn(`⚠ Another zCode instance (PID ${oldPid}) is running — killing stale process`);
|
// Same PID or different process - just log warning, don't kill
|
||||||
process.kill(oldPid, 'SIGTERM');
|
if (oldPid !== process.pid) {
|
||||||
// Wait briefly for cleanup
|
logger.warn(`⚠ Another zCode instance (PID ${oldPid}) is running — keeping this instance (PID ${process.pid})`);
|
||||||
const deadline = Date.now() + 5000;
|
} else {
|
||||||
while (Date.now() < deadline) {
|
logger.info(`✓ Pidfile already acquired by this instance (PID ${process.pid})`);
|
||||||
try { process.kill(oldPid, 0); } catch { break; }
|
|
||||||
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 200);
|
|
||||||
}
|
}
|
||||||
// Force kill if still alive
|
// Don't kill - just continue with current process
|
||||||
try { process.kill(oldPid, 0); process.kill(oldPid, 'SIGKILL'); } catch {}
|
return;
|
||||||
} catch { /* old PID dead, safe */ }
|
} catch { /* old PID dead, safe to acquire */ }
|
||||||
}
|
}
|
||||||
fs.writeFileSync(PIDFILE, process.pid.toString());
|
fs.writeFileSync(PIDFILE, process.pid.toString());
|
||||||
logger.info(`✓ Pidfile acquired: ${PIDFILE} (PID ${process.pid})`);
|
logger.info(`✓ Pidfile acquired: ${PIDFILE} (PID ${process.pid})`);
|
||||||
|
|||||||
Reference in New Issue
Block a user