Skip to content

Commit d75c10a

Browse files
committed
fix(mollifier): bound drainer shutdown so a hung handler can't block exit
Pass a configurable timeout to drainer.stop() so SIGTERM/SIGINT can't hang forever if an in-flight handler is wedged. Matches the precedent set by BATCH_TRIGGER_WORKER_SHUTDOWN_TIMEOUT_MS (default 30s).
1 parent 4b9700b commit d75c10a

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

apps/webapp/app/env.server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,7 @@ const EnvironmentSchema = z
10571057
MOLLIFIER_DRAIN_CONCURRENCY: z.coerce.number().int().positive().default(50),
10581058
MOLLIFIER_ENTRY_TTL_S: z.coerce.number().int().positive().default(600),
10591059
MOLLIFIER_DRAIN_MAX_ATTEMPTS: z.coerce.number().int().positive().default(3),
1060+
MOLLIFIER_DRAIN_SHUTDOWN_TIMEOUT_MS: z.coerce.number().int().positive().default(30_000),
10601061

10611062
BATCH_TRIGGER_PROCESS_JOB_VISIBILITY_TIMEOUT_MS: z.coerce
10621063
.number()

apps/webapp/app/services/worker.server.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,16 @@ export async function init() {
149149
// without a process-global guard, dev hot-reloads would stack a fresh
150150
// listener pair every request. Mirrors the `__worker__` singleton
151151
// pattern above.
152+
// Bound shutdown so a hung handler can't block process exit past the
153+
// pod's termination grace period. `drainer.stop({ timeoutMs })` logs a
154+
// warning and returns if the deadline is hit while a handler is still
155+
// in flight.
152156
const stopDrainer = () => {
153-
drainer.stop().catch((error) => {
154-
logger.error("Failed to stop mollifier drainer", { error });
155-
});
157+
drainer
158+
.stop({ timeoutMs: env.MOLLIFIER_DRAIN_SHUTDOWN_TIMEOUT_MS })
159+
.catch((error) => {
160+
logger.error("Failed to stop mollifier drainer", { error });
161+
});
156162
};
157163
process.once("SIGTERM", stopDrainer);
158164
process.once("SIGINT", stopDrainer);

0 commit comments

Comments
 (0)