




















@@ -88,6 +88,7 @@ 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+const MAX_CONSECUTIVE_STUCK_STATE_RESTARTS = 1;
9192// A flapping advertiser can briefly reach "announced" between probing
9293// failures, which resets the consecutive counter. Bound total restarts too.
9394const RESTART_WINDOW_MS = 30 * 60_000;
@@ -571,6 +572,7 @@ export async function startGatewayBonjourAdvertiser(
571572let recreatePromise: Promise<void> | null = null;
572573let disabled = false;
573574let consecutiveRestarts = 0;
575+let consecutiveStuckStateRestarts = 0;
574576const restartTimestamps: number[] = [];
575577let cycle: BonjourCycle | null = createCycle();
576578const stateTracker = new Map<string, ServiceStateTracker>();
@@ -590,7 +592,7 @@ export async function startGatewayBonjourAdvertiser(
590592}
591593};
592594593-const recreateAdvertiser = async (reason: string) => {
595+const recreateAdvertiser = async (reason: string, opts?: { stuckState?: boolean }) => {
594596if (stopped || disabled) {
595597return;
596598}
@@ -599,6 +601,7 @@ export async function startGatewayBonjourAdvertiser(
599601}
600602recreatePromise = (async () => {
601603consecutiveRestarts += 1;
604+consecutiveStuckStateRestarts = opts?.stuckState ? consecutiveStuckStateRestarts + 1 : 0;
602605const now = Date.now();
603606while (
604607restartTimestamps.length > 0 &&
@@ -608,14 +611,18 @@ export async function startGatewayBonjourAdvertiser(
608611}
609612restartTimestamps.push(now);
610613const tooManyConsecutive = consecutiveRestarts > MAX_CONSECUTIVE_RESTARTS;
614+const tooManyStuckStates =
615+consecutiveStuckStateRestarts > MAX_CONSECUTIVE_STUCK_STATE_RESTARTS;
611616const tooManyInWindow = restartTimestamps.length >= MAX_RESTARTS_IN_WINDOW;
612-if (tooManyConsecutive || tooManyInWindow) {
617+if (tooManyConsecutive || tooManyStuckStates || tooManyInWindow) {
613618disabled = true;
614619const detail = tooManyConsecutive
615620 ? `${MAX_CONSECUTIVE_RESTARTS} failed restarts`
616- : `${MAX_RESTARTS_IN_WINDOW} restarts within ${Math.round(
617- RESTART_WINDOW_MS / 60_000,
618- )} minutes`;
621+ : tooManyStuckStates
622+ ? `${MAX_CONSECUTIVE_STUCK_STATE_RESTARTS} stuck-state restart`
623+ : `${MAX_RESTARTS_IN_WINDOW} restarts within ${Math.round(
624+ RESTART_WINDOW_MS / 60_000,
625+ )} minutes`;
619626logger.warn(
620627`bonjour: disabling advertiser after ${detail} (${reason}); set discovery.mdns.mode="off" or OPENCLAW_DISABLE_BONJOUR=1 to disable mDNS discovery`,
621628);
@@ -661,6 +668,7 @@ export async function startGatewayBonjourAdvertiser(
661668}
662669if (stateUnknown === "announced") {
663670consecutiveRestarts = 0;
671+consecutiveStuckStateRestarts = 0;
664672}
665673const tracked = stateTracker.get(label);
666674if (
@@ -673,6 +681,7 @@ export async function startGatewayBonjourAdvertiser(
673681 label,
674682 svc,
675683 )})`,
684+{ stuckState: true },
676685);
677686return;
678687}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。