relay: don't crash when webchat port is busy

This commit is contained in:
Peter Steinberger
2025-12-08 23:49:47 +00:00
parent b7b1714f32
commit 36c91c3984
2 changed files with 1754 additions and 1751 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -14,7 +14,7 @@ import {
resolveStorePath,
type SessionEntry,
} from "../config/sessions.js";
import { logDebug } from "../logger.js";
import { logDebug, logError } from "../logger.js";
import type { RuntimeEnv } from "../runtime.js";
const WEBCHAT_DEFAULT_PORT = 18788;
@@ -421,6 +421,12 @@ export async function startWebChatServer(port = WEBCHAT_DEFAULT_PORT) {
await new Promise<void>((resolve, reject) => {
server.once("error", reject);
server.listen(port, "127.0.0.1", () => resolve());
}).catch((err) => {
const code = (err as NodeJS.ErrnoException).code;
const msg = code ? `${code}: ${String(err)}` : String(err);
logError(
`webchat server failed to bind 127.0.0.1:${port} (${msg}); continuing without webchat`,
);
});
// WebSocket setup for live session updates.