-
-
Notifications
You must be signed in to change notification settings - Fork 66
Fix large-negative setTimeout delay causing allowPast jobs to never fire in Deno #369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
956f649
5e06563
9d31329
b45c147
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -499,6 +499,13 @@ class Cron<T = undefined> { | |
| waitMs = maxDelay; | ||
| } | ||
|
|
||
| // Clamp negative delays to 0 - some runtimes (e.g. Deno) treat large negative values | ||
| // as large positive delays due to 32-bit integer overflow, causing jobs with allowPast:true | ||
| // and a far-past date to never fire. Use a backoff when paused to avoid a tight loop. | ||
| if (waitMs < 0) { | ||
| waitMs = this._states.paused ? 1000 : 0; | ||
| } | ||
|
Comment on lines
+503
to
+507
|
||
|
|
||
| // Start the timer loop | ||
| // _checkTrigger will either call _trigger (if it's time, croner isn't paused and whatever), | ||
| // or recurse back to this function to wait for next trigger | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clamping negative
waitMsto0can create a tight rescheduling loop when the job is paused and the target time is already in the past (e.g.paused: true+allowPast: true+ far-past once date). In that case_checkTriggernever fires becausepaused, butschedule()keeps computing a negative delay and schedulingsetTimeout(..., 0)repeatedly, which can cause high CPU usage. Consider adding a small backoff when paused/overdue (or changing pause/resume behavior to avoid rescheduling while paused).