From 46ce666b0429e2c546a038b38d34cbece0cad71b Mon Sep 17 00:00:00 2001 From: Ayaan Zaidi Date: Thu, 23 Apr 2026 07:39:44 +0530 Subject: [PATCH] fix(gateway): keep restart emitting after ack prep failure --- src/infra/infra-runtime.test.ts | 21 +++++++++++++++++++++ src/infra/restart.ts | 3 +-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/infra/infra-runtime.test.ts b/src/infra/infra-runtime.test.ts index c7861bda72c..2eff8dc0ba1 100644 --- a/src/infra/infra-runtime.test.ts +++ b/src/infra/infra-runtime.test.ts @@ -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 = () => {}; diff --git a/src/infra/restart.ts b/src/infra/restart.ts index 054805794c3..03c45fc5350 100644 --- a/src/infra/restart.ts +++ b/src/infra/restart.ts @@ -206,8 +206,7 @@ async function emitPreparedGatewayRestart(hooks?: RestartEmitHooks): Promise