
























@@ -88,6 +88,10 @@ const REPAIR_DEBOUNCE_MS = 30_000;
8888// See https://github.com/openclaw/openclaw/issues/72481
8989const STUCK_ANNOUNCING_MS = 20_000;
9090const MAX_CONSECUTIVE_RESTARTS = 3;
91+// A flapping advertiser can briefly reach "announced" between probing
92+// failures, which resets the consecutive counter. Bound total restarts too.
93+const RESTART_WINDOW_MS = 30 * 60_000;
94+const MAX_RESTARTS_IN_WINDOW = 5;
9195const BONJOUR_ANNOUNCED_STATE = "announced";
9296const CIAO_SELF_PROBE_RETRY_FRAGMENT =
9397"failed probing with reason: Error: Can't probe for a service which is announced already.";
@@ -563,6 +567,7 @@ export async function startGatewayBonjourAdvertiser(
563567let recreatePromise: Promise<void> | null = null;
564568let disabled = false;
565569let consecutiveRestarts = 0;
570+const restartTimestamps: number[] = [];
566571let cycle: BonjourCycle | null = createCycle();
567572const stateTracker = new Map<string, ServiceStateTracker>();
568573@@ -590,10 +595,25 @@ export async function startGatewayBonjourAdvertiser(
590595}
591596recreatePromise = (async () => {
592597consecutiveRestarts += 1;
593-if (consecutiveRestarts > MAX_CONSECUTIVE_RESTARTS) {
598+const now = Date.now();
599+while (
600+restartTimestamps.length > 0 &&
601+now - (restartTimestamps[0] ?? 0) > RESTART_WINDOW_MS
602+) {
603+restartTimestamps.shift();
604+}
605+restartTimestamps.push(now);
606+const tooManyConsecutive = consecutiveRestarts > MAX_CONSECUTIVE_RESTARTS;
607+const tooManyInWindow = restartTimestamps.length >= MAX_RESTARTS_IN_WINDOW;
608+if (tooManyConsecutive || tooManyInWindow) {
594609disabled = true;
610+const detail = tooManyConsecutive
611+ ? `${MAX_CONSECUTIVE_RESTARTS} failed restarts`
612+ : `${MAX_RESTARTS_IN_WINDOW} restarts within ${Math.round(
613+ RESTART_WINDOW_MS / 60_000,
614+ )} minutes`;
595615logger.warn(
596-`bonjour: disabling advertiser after ${MAX_CONSECUTIVE_RESTARTS} failed restarts (${reason}); set discovery.mdns.mode="off" or OPENCLAW_DISABLE_BONJOUR=1 to disable mDNS discovery`,
616+`bonjour: disabling advertiser after ${detail} (${reason}); set discovery.mdns.mode="off" or OPENCLAW_DISABLE_BONJOUR=1 to disable mDNS discovery`,
597617);
598618const previous = cycle;
599619cycle = null;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。