function postRestartHealthAttempts(): number { return process.platform === "win32"
? Math.ceil(WINDOWS_POST_RESTART_HEALTH_TIMEOUT_MS / POST_RESTART_HEALTH_DELAY_MS)
: POST_RESTART_HEALTH_ATTEMPTS;
}
function formatRestartFailure(params: {
health: GatewayRestartSnapshot;
port: number;
timeoutSeconds: number;
}): { statusLine: string; failMessage: string } { if (params.health.waitOutcome === "stopped-free") { const elapsedSeconds = Math.max(1, Math.round((params.health.elapsedMs ?? 0) / 1000)); return {
statusLine: `Gateway restart failed after ${elapsedSeconds}s: service stayed stopped and port ${params.port} stayed free.`,
failMessage: `Gateway restart failed after ${elapsedSeconds}s: service stayed stopped and health checks never came up.`,
};
}
return {
statusLine: `Timed out after ${params.timeoutSeconds}s waiting for gateway port ${params.port} to become healthy.`,
failMessage: `Gateway restart timed out after ${params.timeoutSeconds}s waiting for health checks.`,
};
}
if (!probe?.ok) { return;
} if (!isRestartEnabled(probe.configSnapshot as { commands?: unknown } | undefined)) { thrownew Error( "Gateway restart is disabled in the running gateway config (commands.restart=false); unmanaged SIGUSR1 restart would be ignored",
);
}
}
function resolveVerifiedGatewayListenerPids(port: number): number[] { return findVerifiedGatewayListenerPidsOnPortSync(port).filter(
(pid): pid is number => Number.isFinite(pid) && pid > 0,
);
}
async function stopGatewayWithoutServiceManager(port: number) { const pids = resolveVerifiedGatewayListenerPids(port); if (pids.length === 0) { returnnull;
} for (const pid of pids) {
signalVerifiedGatewayPidSync(pid, "SIGTERM");
} return {
result: "stopped" as const,
message: `Gateway stop signal sent to unmanaged process${pids.length === 1 ? "" : "es"} on port ${port}: ${formatGatewayPidList(pids)}.`,
};
}
async function restartGatewayWithoutServiceManager(port: number) {
await assertUnmanagedGatewayRestartEnabled(port); const pids = resolveVerifiedGatewayListenerPids(port); if (pids.length === 0) { returnnull;
} if (pids.length > 1) { thrownew Error(
`multiple gateway processes are listening on port ${port}: ${formatGatewayPidList(pids)}; use "openclaw gateway status --deep" before retrying restart`,
);
}
signalVerifiedGatewayPidSync(pids[0], "SIGUSR1"); return {
result: "restarted" as const,
message: `Gateway restart signal sent to unmanaged process on port ${port}: ${pids[0]}.`,
};
}
const diagnostics = renderGatewayPortHealthDiagnostics(health); const timeoutLine = `Timed out after ${restartWaitSeconds}s waiting for gateway port ${restartPort} to become healthy.`; if (!json) {
defaultRuntime.log(theme.warn(timeoutLine)); for (const line of diagnostics) {
defaultRuntime.log(theme.muted(line));
}
} else {
warnings.push(timeoutLine);
warnings.push(...diagnostics);
}
fail(`Gateway restart timed out after ${restartWaitSeconds}s waiting for health checks.`, [
formatCliCommand("openclaw gateway status --deep"),
formatCliCommand("openclaw doctor"),
]); thrownew Error("unreachable after gateway restart health failure");
}
let health = await waitForGatewayHealthyRestart({
service,
port: restartPort,
attempts: restartHealthAttempts,
delayMs: POST_RESTART_HEALTH_DELAY_MS,
includeUnknownListenersAsStale: process.platform === "win32",
});
if (!health.healthy && health.staleGatewayPids.length > 0) { const staleMsg = `Found stale gateway process(es): ${health.staleGatewayPids.join(", ")}.`;
warnings.push(staleMsg); if (!json) {
defaultRuntime.log(theme.warn(staleMsg));
defaultRuntime.log(theme.muted("Stopping stale process(es) and retrying restart..."));
}
const diagnostics = renderRestartDiagnostics(health); const failure = formatRestartFailure({
health,
port: restartPort,
timeoutSeconds: restartWaitSeconds,
}); const runningNoPortLine =
health.runtime.status === "running" && health.portUsage.status === "free"
? `Gateway process is running but port ${restartPort} is still free (startup hang/crash loop or very slow VM startup).`
: null; if (!json) {
defaultRuntime.log(theme.warn(failure.statusLine)); if (runningNoPortLine) {
defaultRuntime.log(theme.warn(runningNoPortLine));
} for (const line of diagnostics) {
defaultRuntime.log(theme.muted(line));
}
} else {
warnings.push(failure.statusLine); if (runningNoPortLine) {
warnings.push(runningNoPortLine);
}
warnings.push(...diagnostics);
}
fail(failure.failMessage, [
formatCliCommand("openclaw gateway status --deep"),
formatCliCommand("openclaw doctor"),
]); thrownew Error("unreachable after gateway restart failure");
},
});
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.9 Sekunden
(vorverarbeitet am 2026-06-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.