fix: tighten gateway restart loop handling (#23416) (thanks @jeffwnli)
This commit is contained in:
@@ -11,7 +11,9 @@ const markGatewaySigusr1RestartHandled = vi.fn();
|
||||
const getActiveTaskCount = vi.fn(() => 0);
|
||||
const waitForActiveTasks = vi.fn(async (_timeoutMs: number) => ({ drained: true }));
|
||||
const resetAllLanes = vi.fn();
|
||||
const restartGatewayProcessWithFreshPid = vi.fn(() => ({ mode: "skipped" as const }));
|
||||
const restartGatewayProcessWithFreshPid = vi.fn<
|
||||
() => { mode: "spawned" | "supervised" | "disabled" | "failed"; pid?: number; detail?: string }
|
||||
>(() => ({ mode: "disabled" }));
|
||||
const DRAIN_TIMEOUT_LOG = "drain timeout reached; proceeding with restart";
|
||||
const gatewayLog = {
|
||||
info: vi.fn(),
|
||||
@@ -30,8 +32,7 @@ vi.mock("../../infra/restart.js", () => ({
|
||||
}));
|
||||
|
||||
vi.mock("../../infra/process-respawn.js", () => ({
|
||||
restartGatewayProcessWithFreshPid: (...args: unknown[]) =>
|
||||
restartGatewayProcessWithFreshPid(...args),
|
||||
restartGatewayProcessWithFreshPid: () => restartGatewayProcessWithFreshPid(),
|
||||
}));
|
||||
|
||||
vi.mock("../../process/command-queue.js", () => ({
|
||||
@@ -140,6 +141,7 @@ describe("runGatewayLoop", () => {
|
||||
});
|
||||
expect(markGatewaySigusr1RestartHandled).toHaveBeenCalledTimes(2);
|
||||
expect(resetAllLanes).toHaveBeenCalledTimes(2);
|
||||
expect(acquireGatewayLock).toHaveBeenCalledTimes(3);
|
||||
} finally {
|
||||
removeNewSignalListeners("SIGTERM", beforeSigterm);
|
||||
removeNewSignalListeners("SIGINT", beforeSigint);
|
||||
@@ -153,8 +155,6 @@ describe("runGatewayLoop", () => {
|
||||
const lockRelease = vi.fn(async () => {});
|
||||
acquireGatewayLock.mockResolvedValueOnce({
|
||||
release: lockRelease,
|
||||
lockPath: "/tmp/test.lock",
|
||||
configPath: "/test/openclaw.json",
|
||||
});
|
||||
|
||||
// Override process-respawn to return "spawned" mode
|
||||
|
||||
Reference in New Issue
Block a user