From 7f4248e5e0bb805f3b885b53f0d22b1a2eb0eac8 Mon Sep 17 00:00:00 2001 From: Emanuel Stadler <9994339+emanuelst@users.noreply.github.com> Date: Wed, 7 Jan 2026 18:39:35 +0100 Subject: [PATCH] Cron: clamp timer to avoid TimeoutOverflowWarning --- src/cron/service.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cron/service.ts b/src/cron/service.ts index cdda4bc51..a75cc9ae6 100644 --- a/src/cron/service.ts +++ b/src/cron/service.ts @@ -44,6 +44,7 @@ export type CronServiceDeps = { }; const STUCK_RUN_MS = 2 * 60 * 60 * 1000; +const MAX_TIMEOUT_MS = 2 ** 31 - 1; function normalizeRequiredName(raw: unknown) { if (typeof raw !== "string") throw new Error("cron job name is required"); @@ -393,11 +394,13 @@ export class CronService { const nextAt = this.nextWakeAtMs(); if (!nextAt) return; const delay = Math.max(nextAt - this.deps.nowMs(), 0); + // Avoid TimeoutOverflowWarning when a job is far in the future. + const clampedDelay = Math.min(delay, MAX_TIMEOUT_MS); this.timer = setTimeout(() => { void this.onTimer().catch((err) => { this.deps.log.error({ err: String(err) }, "cron: timer tick failed"); }); - }, delay); + }, clampedDelay); this.timer.unref?.(); }