Bonjour: ignore ciao cancellation rejections

This commit is contained in:
Emanuel Stadler
2026-01-07 20:35:19 +01:00
committed by Peter Steinberger
parent d6608196d4
commit 9056e0edbb
2 changed files with 20 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ import { normalizeEnv } from "../infra/env.js";
import { isMainModule } from "../infra/is-main.js";
import { ensureClawdbotCliOnPath } from "../infra/path-env.js";
import { assertSupportedRuntime } from "../infra/runtime-guard.js";
import { isUnhandledRejectionHandled } from "../infra/unhandled-rejections.js";
import { enableConsoleCapture } from "../logging.js";
export async function runCli(argv: string[] = process.argv) {
@@ -25,6 +26,7 @@ export async function runCli(argv: string[] = process.argv) {
// Global error handlers to prevent silent crashes from unhandled rejections/exceptions.
// These log the error and exit gracefully instead of crashing without trace.
process.on("unhandledRejection", (reason, _promise) => {
if (isUnhandledRejectionHandled(reason)) return;
console.error(
"[clawdbot] Unhandled promise rejection:",
reason instanceof Error ? (reason.stack ?? reason.message) : reason,

View File

@@ -2,6 +2,7 @@ import os from "node:os";
import { logDebug, logWarn } from "../logger.js";
import { getLogger } from "../logging.js";
import { registerUnhandledRejectionHandler } from "./unhandled-rejections.js";
export type GatewayBonjourAdvertiser = {
stop: () => Promise<void>;
@@ -143,6 +144,22 @@ export async function startGatewayBonjourAdvertiser(
});
}
let ciaoCancellationRejectionHandler: (() => void) | undefined;
if (services.length > 0) {
ciaoCancellationRejectionHandler = registerUnhandledRejectionHandler(
(reason) => {
const message = formatBonjourError(reason).toUpperCase();
if (!message.includes("CIAO ANNOUNCEMENT CANCELLED")) {
return false;
}
logDebug(
`bonjour: ignoring unhandled ciao rejection: ${formatBonjourError(reason)}`,
);
return true;
},
);
}
logDebug(
`bonjour: starting (hostname=${hostname}, instance=${JSON.stringify(
safeServiceName(instanceName),
@@ -250,6 +267,7 @@ export async function startGatewayBonjourAdvertiser(
/* ignore */
}
}
ciaoCancellationRejectionHandler?.();
try {
await responder.shutdown();
} catch {