fix(gateway): keep restart emitting after ack prep failure

This commit is contained in:
Ayaan Zaidi
2026-04-23 07:39:44 +05:30
parent fe5f0cddb9
commit 46ce666b04
2 changed files with 22 additions and 2 deletions

View File

@@ -133,6 +133,27 @@ describe("infra runtime", () => {
expect(afterEmitRejected).toHaveBeenCalledTimes(1);
});
it("still emits restart when preparation fails", async () => {
const beforeEmit = vi.fn(async () => {
throw new Error("state dir readonly");
});
const emitSpy = vi.spyOn(process, "emit");
const handler = () => {};
process.on("SIGUSR1", handler);
try {
scheduleGatewaySigusr1Restart({
delayMs: 0,
emitHooks: { beforeEmit },
});
await vi.advanceTimersByTimeAsync(0);
expect(beforeEmit).toHaveBeenCalledTimes(1);
expect(emitSpy).toHaveBeenCalledWith("SIGUSR1");
} finally {
process.removeListener("SIGUSR1", handler);
}
});
it("applies restart cooldown between emitted restart cycles", async () => {
const emitSpy = vi.spyOn(process, "emit");
const handler = () => {};

View File

@@ -206,8 +206,7 @@ async function emitPreparedGatewayRestart(hooks?: RestartEmitHooks): Promise<voi
try {
await hooks?.beforeEmit?.();
} catch (err) {
restartLog.warn(`restart preparation failed; restart not emitted: ${String(err)}`);
return;
restartLog.warn(`restart preparation failed; restart will continue without it: ${String(err)}`);
}
const emitted = emitGatewayRestart();