diff --git a/src/infra/bonjour-ciao.test.ts b/src/infra/bonjour-ciao.test.ts index d3acc4a2c73..3d9ec83f0f4 100644 --- a/src/infra/bonjour-ciao.test.ts +++ b/src/infra/bonjour-ciao.test.ts @@ -9,7 +9,7 @@ vi.mock("../logger.js", () => ({ const { ignoreCiaoCancellationRejection } = await import("./bonjour-ciao.js"); describe("bonjour-ciao", () => { - it("ignores and logs ciao cancellation rejections", () => { + it("ignores and logs ciao announcement cancellation rejections", () => { expect( ignoreCiaoCancellationRejection(new Error("Ciao announcement cancelled by shutdown")), ).toBe(true); @@ -18,6 +18,15 @@ describe("bonjour-ciao", () => { ); }); + it("ignores and logs ciao probing cancellation rejections", () => { + logDebugMock.mockReset(); + + expect(ignoreCiaoCancellationRejection(new Error("CIAO PROBING CANCELLED"))).toBe(true); + expect(logDebugMock).toHaveBeenCalledWith( + expect.stringContaining("ignoring unhandled ciao rejection"), + ); + }); + it("ignores lower-case string cancellation reasons too", () => { logDebugMock.mockReset(); diff --git a/src/infra/bonjour-ciao.ts b/src/infra/bonjour-ciao.ts index 878997c6203..f39902c0aa7 100644 --- a/src/infra/bonjour-ciao.ts +++ b/src/infra/bonjour-ciao.ts @@ -1,9 +1,11 @@ import { logDebug } from "../logger.js"; import { formatBonjourError } from "./bonjour-errors.js"; +const CIAO_CANCELLATION_MESSAGE_RE = /^CIAO (?:ANNOUNCEMENT|PROBING) CANCELLED\b/u; + export function ignoreCiaoCancellationRejection(reason: unknown): boolean { const message = formatBonjourError(reason).toUpperCase(); - if (!message.includes("CIAO ANNOUNCEMENT CANCELLED")) { + if (!CIAO_CANCELLATION_MESSAGE_RE.test(message)) { return false; } logDebug(`bonjour: ignoring unhandled ciao rejection: ${formatBonjourError(reason)}`);