From b806783e0954a9eae9ef7ac6c873977f6b5f2921 Mon Sep 17 00:00:00 2001 From: cici1029 Date: Thu, 29 Jan 2026 15:04:04 +0800 Subject: [PATCH] fix: ignore mDNS socket errors to prevent gateway crashes Extended ignoreCiaoCancellationRejection to also handle announcement socket errors which are non-fatal and caused by network interface issues. Previously, these unhandled promise rejections would crash the gateway every ~2 minutes when mDNS announcements failed due to EAFNOSUPPORT socket errors. The fix allows the gateway to continue running normally even when mDNS discovery is unavailable, since mDNS is only used for local network discovery and not required for core gateway functionality. Testing: Gateway remained stable for 150+ seconds after fix, compared to crashing every ~120 seconds before (macOS 15.2 with HTTP_PROXY). --- src/infra/bonjour-ciao.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/infra/bonjour-ciao.ts b/src/infra/bonjour-ciao.ts index 17df4e78c..6734071bc 100644 --- a/src/infra/bonjour-ciao.ts +++ b/src/infra/bonjour-ciao.ts @@ -4,9 +4,15 @@ import { formatBonjourError } from "./bonjour-errors.js"; export function ignoreCiaoCancellationRejection(reason: unknown): boolean { const message = formatBonjourError(reason).toUpperCase(); - if (!message.includes("CIAO ANNOUNCEMENT CANCELLED")) { - return false; + // Ignore ciao cancellation rejections (normal cleanup) + if (message.includes("CIAO ANNOUNCEMENT CANCELLED")) { + logDebug(`bonjour: ignoring unhandled ciao rejection: ${formatBonjourError(reason)}`); + return true; } - logDebug(`bonjour: ignoring unhandled ciao rejection: ${formatBonjourError(reason)}`); - return true; + // Ignore socket errors from mDNS announcements (non-fatal, can happen due to network issues) + if (message.includes("ANNOUNCEMENT FAILED") && message.includes("SOCKET ERRORS")) { + logDebug(`bonjour: ignoring mDNS socket error: ${formatBonjourError(reason)}`); + return true; + } + return false; }