diff --git a/src/bot/index.js b/src/bot/index.js index b521f4f9..6522efa7 100644 --- a/src/bot/index.js +++ b/src/bot/index.js @@ -38,17 +38,15 @@ function acquirePidfile() { const oldPid = parseInt(fs.readFileSync(PIDFILE, 'utf8').trim()); // Check if old process is still alive try { process.kill(oldPid, 0); - logger.warn(`⚠ Another zCode instance (PID ${oldPid}) is running — killing stale process`); - process.kill(oldPid, 'SIGTERM'); - // Wait briefly for cleanup - const deadline = Date.now() + 5000; - while (Date.now() < deadline) { - try { process.kill(oldPid, 0); } catch { break; } - Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 200); + // Same PID or different process - just log warning, don't kill + if (oldPid !== process.pid) { + logger.warn(`⚠ Another zCode instance (PID ${oldPid}) is running — keeping this instance (PID ${process.pid})`); + } else { + logger.info(`✓ Pidfile already acquired by this instance (PID ${process.pid})`); } - // Force kill if still alive - try { process.kill(oldPid, 0); process.kill(oldPid, 'SIGKILL'); } catch {} - } catch { /* old PID dead, safe */ } + // Don't kill - just continue with current process + return; + } catch { /* old PID dead, safe to acquire */ } } fs.writeFileSync(PIDFILE, process.pid.toString()); logger.info(`✓ Pidfile acquired: ${PIDFILE} (PID ${process.pid})`);