fix: move PortManager init after PORT/httpServer declaration
This commit is contained in:
@@ -1419,15 +1419,7 @@ export async function initBot(config, api, tools, skills, agents) {
|
|||||||
|
|
||||||
// ── (unhandled rejection handler registered below with gracefulShutdown) ──
|
// ── (unhandled rejection handler registered below with gracefulShutdown) ──
|
||||||
|
|
||||||
// ── PortManager: smart port lifecycle (claim, retry, recover) ──
|
// ── Graceful shutdown is defined at end of initBot (requires full `svc`) ──
|
||||||
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,
|
|
||||||
});
|
|
||||||
|
|
||||||
// ── Express + WebSocket server (keep for webhook compatibility) ──
|
// ── Express + WebSocket server (keep for webhook compatibility) ──
|
||||||
const app = express();
|
const app = express();
|
||||||
@@ -1482,6 +1474,16 @@ export async function initBot(config, api, tools, skills, agents) {
|
|||||||
|
|
||||||
const PORT = process.env.ZCODE_PORT || 3000;
|
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) ──
|
// ── Claim port via PortManager (retry + stale recovery + backoff) ──
|
||||||
try {
|
try {
|
||||||
await portManager.claim(httpServer);
|
await portManager.claim(httpServer);
|
||||||
|
|||||||
Reference in New Issue
Block a user