fix: move PortManager init after PORT/httpServer declaration

This commit is contained in:
Kilo
2026-05-06 18:11:22 +00:00
Unverified
parent 1447c48e93
commit c372ae6bae

View File

@@ -1419,15 +1419,7 @@ export async function initBot(config, api, tools, skills, agents) {
// ── (unhandled rejection handler registered below with gracefulShutdown) ──
// ── PortManager: smart port lifecycle (claim, retry, recover) ──
const PIDFILE = path.join(process.env.HOME || '/tmp', '.zcode-bot.pid');
const portManager = new PortManager({
port: PORT,
pidfile: PIDFILE,
maxAttempts: 5,
baseDelayMs: 500,
maxDelayMs: 5000,
});
// ── Graceful shutdown is defined at end of initBot (requires full `svc`) ──
// ── Express + WebSocket server (keep for webhook compatibility) ──
const app = express();
@@ -1482,6 +1474,16 @@ export async function initBot(config, api, tools, skills, agents) {
const PORT = process.env.ZCODE_PORT || 3000;
// ── PortManager: smart port lifecycle (claim, retry, recover) ──
const PIDFILE = path.join(process.env.HOME || '/tmp', '.zcode-bot.pid');
const portManager = new PortManager({
port: PORT,
pidfile: PIDFILE,
maxAttempts: 5,
baseDelayMs: 500,
maxDelayMs: 5000,
});
// ── Claim port via PortManager (retry + stale recovery + backoff) ──
try {
await portManager.claim(httpServer);