Skip to content

Commit fa5fb18

Browse files
committed
fix: clamp stuck threshold to fallback ceiling to prevent setTimeout overflow
1 parent 822a3b0 commit fa5fb18

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/cron/service/jobs.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,13 @@ function normalizeJobTickState(params: { state: CronServiceState; job: CronJob;
385385
const runningAt = job.state.runningAtMs;
386386
if (typeof runningAt === "number") {
387387
const jobTimeoutMs = resolveCronJobTimeoutMs(job);
388+
// Clamp to the fallback ceiling so absurdly large timeoutSeconds values
389+
// (which overflow setTimeout's 2^31-1 ms limit) don't leave stuck locks
390+
// blocking the job for days after a crash.
388391
const stuckThresholdMs =
389-
typeof jobTimeoutMs === "number" ? jobTimeoutMs + STUCK_RUN_BUFFER_MS : STUCK_RUN_FALLBACK_MS;
392+
typeof jobTimeoutMs === "number"
393+
? Math.min(jobTimeoutMs + STUCK_RUN_BUFFER_MS, STUCK_RUN_FALLBACK_MS)
394+
: STUCK_RUN_FALLBACK_MS;
390395
if (nowMs - runningAt > stuckThresholdMs) {
391396
state.deps.log.warn(
392397
{ jobId: job.id, runningAtMs: runningAt, stuckThresholdMs },

0 commit comments

Comments
 (0)