fix: allow slower Windows gateway restart health

This commit is contained in:
Peter Steinberger
2026-04-05 18:20:19 +01:00
parent 6008ed6c24
commit 5ad27fa25f
2 changed files with 40 additions and 1 deletions

View File

@@ -278,6 +278,34 @@ describe("inspectGatewayRestart", () => {
expect(sleep).toHaveBeenCalledTimes(25);
});
it("waits longer before stopped-free early exit on Windows", async () => {
Object.defineProperty(process, "platform", { value: "win32", configurable: true });
const service = makeGatewayService({ status: "stopped" });
inspectPortUsage.mockResolvedValue({
port: 18789,
status: "free",
listeners: [],
hints: [],
});
const { waitForGatewayHealthyRestart } = await import("./restart-health.js");
const snapshot = await waitForGatewayHealthyRestart({
service,
port: 18789,
attempts: 120,
delayMs: 500,
});
expect(snapshot).toMatchObject({
healthy: false,
runtime: { status: "stopped" },
portUsage: { status: "free" },
waitOutcome: "stopped-free",
elapsedMs: 27_500,
});
expect(sleep).toHaveBeenCalledTimes(55);
});
it("annotates timeout waits when the health loop exhausts all attempts", async () => {
const service = makeGatewayService({ status: "running", pid: 8000 });
inspectPortUsage.mockResolvedValue({

View File

@@ -15,6 +15,8 @@ export const DEFAULT_RESTART_HEALTH_DELAY_MS = 500;
export const DEFAULT_RESTART_HEALTH_ATTEMPTS = Math.ceil(
DEFAULT_RESTART_HEALTH_TIMEOUT_MS / DEFAULT_RESTART_HEALTH_DELAY_MS,
);
const STOPPED_FREE_EARLY_EXIT_GRACE_MS = 10_000;
const WINDOWS_STOPPED_FREE_EARLY_EXIT_GRACE_MS = 25_000;
export type GatewayRestartWaitOutcome = "healthy" | "stale-pids" | "stopped-free" | "timeout";
@@ -217,6 +219,12 @@ function shouldEarlyExitStoppedFree(
);
}
function stoppedFreeEarlyExitGraceMs(): number {
return process.platform === "win32"
? WINDOWS_STOPPED_FREE_EARLY_EXIT_GRACE_MS
: STOPPED_FREE_EARLY_EXIT_GRACE_MS;
}
function withWaitContext(
snapshot: GatewayRestartSnapshot,
waitOutcome: GatewayRestartWaitOutcome,
@@ -245,7 +253,10 @@ export async function waitForGatewayHealthyRestart(params: {
let consecutiveStoppedFreeCount = 0;
const STOPPED_FREE_THRESHOLD = 6;
const minAttemptForEarlyExit = Math.min(Math.ceil(10_000 / delayMs), Math.floor(attempts / 2));
const minAttemptForEarlyExit = Math.min(
Math.ceil(stoppedFreeEarlyExitGraceMs() / delayMs),
Math.floor(attempts / 2),
);
for (let attempt = 0; attempt < attempts; attempt += 1) {
if (snapshot.healthy) {