Skip to content

Commit e7d040a

Browse files
committed
fix(webapp): close the snapshot store clients on shutdown
The snapshot store connections and the orphan sweeper now close on SIGTERM and SIGINT, matching the other Redis-backed singletons.
1 parent 663b344 commit e7d040a

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

apps/webapp/app/v3/snapshotStoreWiring.server.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import { SnapshotOrphanSweeper } from "@internal/run-store";
22
import { env } from "~/env.server";
33
import { logger } from "~/services/logger.server";
4+
import { signalsEmitter } from "~/services/signals.server";
45
import { engine } from "./runEngine.server";
56
import { runStoreWithoutSnapshotDecorator } from "./runStore.server";
67
import { buildSnapshotSweepRunner } from "./snapshotSweepRunner.server";
78
import { setSnapshotRepairEnqueuer, setSnapshotSweepRunner } from "./snapshotStoreBindings.server";
8-
import { getSnapshotSweepClient, registerSnapshotStoreQuit } from "./snapshotStoreInstance.server";
9+
import {
10+
getSnapshotSweepClient,
11+
quitSnapshotStoreClients,
12+
registerSnapshotStoreQuit,
13+
} from "./snapshotStoreInstance.server";
914

1015
/**
1116
* The third module: it imports both sides, so neither the run store nor the engine has to import
@@ -43,6 +48,16 @@ export function registerSnapshotStoreWiring(): boolean {
4348

4449
registerSnapshotStoreQuit(() => sweeper.quit());
4550

51+
// Close the sweeper and all three connections on the way out, the same way the other Redis-backed
52+
// singletons do. `quitSnapshotStoreClients` is async and the signals emitter swallows listener
53+
// rejections, so discard the promise explicitly rather than handing it a floating one. The caller
54+
// wraps this function in `singleton`, so the listeners are registered once per process.
55+
const onShutdown = (): void => {
56+
void quitSnapshotStoreClients();
57+
};
58+
signalsEmitter.on("SIGTERM", onShutdown);
59+
signalsEmitter.on("SIGINT", onShutdown);
60+
4661
logger.info("snapshot store wiring registered");
4762
return true;
4863
}

0 commit comments

Comments
 (0)