Skip to content

Commit 0d12e7b

Browse files
committed
refactor(webapp): wire mollifier drainer shutdown through signalsEmitter
`process.once("SIGTERM", stopDrainer)` was the odd one out — every other webapp service (runsReplicationInstance, llmPricingRegistry, dynamicFlushScheduler, marqs, eventLoopMonitor) registers through `signalsEmitter` from `~/services/signals.server`, an EventEmitter backed by a single `process.on()` that fans out to all listeners. Switching gets us: - codebase consistency; - `.on` (not `.once`) so a second SIGTERM, if the orchestrator emits one before SIGKILL, still reaches us; - if SIGTERM lands in the narrow gap between the listener attaching and drainer.start() below, the first invocation no-ops (stop() returns early because isRunning is false) but the listener stays attached for any subsequent signal, instead of being consumed and leaving the now-running drainer with no graceful-stop path.
1 parent 92d0841 commit 0d12e7b

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { env } from "~/env.server";
22
import { logger } from "~/services/logger.server";
3+
import { signalsEmitter } from "~/services/signals.server";
34
import { getMollifierDrainer } from "./mollifier/mollifierDrainer.server";
45

56
declare global {
@@ -52,15 +53,28 @@ export function initMollifierDrainerWorker(): void {
5253
// entry.server.tsx, which Remix dev re-evaluates on every change).
5354
// Same guard owns both the handler registration and the start()
5455
// call so the two never get out of sync.
56+
//
57+
// Registers through `signalsEmitter` (the webapp-wide singleton in
58+
// `~/services/signals.server`) rather than `process.once` directly:
59+
// - matches the codebase convention (runsReplicationInstance,
60+
// llmPricingRegistry, dynamicFlushScheduler etc. all listen on
61+
// the same emitter);
62+
// - `.on` (not `.once`) means a second SIGTERM still reaches us if
63+
// the orchestrator delivers more than one signal before SIGKILL;
64+
// - if SIGTERM lands in the gap between this listener attaching
65+
// and `drainer.start()` below, the first invocation no-ops
66+
// (stop() returns early because the drainer isn't running yet)
67+
// but the listener stays attached for a subsequent signal,
68+
// rather than being consumed by `once`.
5569
const stopDrainer = () => {
5670
drainer
5771
.stop({ timeoutMs: env.TRIGGER_MOLLIFIER_DRAIN_SHUTDOWN_TIMEOUT_MS })
5872
.catch((error) => {
5973
logger.error("Failed to stop mollifier drainer", { error });
6074
});
6175
};
62-
process.once("SIGTERM", stopDrainer);
63-
process.once("SIGINT", stopDrainer);
76+
signalsEmitter.on("SIGTERM", stopDrainer);
77+
signalsEmitter.on("SIGINT", stopDrainer);
6478
global.__mollifierShutdownRegistered__ = true;
6579
drainer.start();
6680
}

0 commit comments

Comments
 (0)