Skip to content

fix(taskhelper): stop the cron runner when no next execution date exists - #382

Merged
Nexucis merged 1 commit into
perses:mainfrom
ToniAdreal:toni-377-followup
Nov 12, 2026
Merged

Nexucis merged 1 commit into
perses:mainfrom
ToniAdreal:toni-377-followup

Conversation

@ToniAdreal

Copy link
Copy Markdown
Contributor

Follow-up to #377 (and #4732). The creation-time check in NewCron rejects schedules that never match any date, but Schedule.Next can still return the zero time after a firing: it only searches five years ahead, so a leap-day schedule such as 0 0 29 2 * passes the creation check yet has no match within five years after the 2096-02-29 firing (the next match is 2104-02-29, an 8-year gap because 2100 is not a leap year). Arming a timer with the resulting negative duration would execute the task in a busy loop.

This adds a belt-and-braces guard in cron(): if next.IsZero(), log an error and stop the runner instead of arming the timer. The guard is checked at the top of the loop, so it covers both the initial Next and the one computed after each execution.

Test: TestCron_StopsWhenNoNextExecutionDate builds the runner directly with a never-matching schedule (NewCron rejects it) and asserts the task never executes, the runner stops promptly, and an error is logged. Verified locally: the test passes with the guard and fails without it (the runner never stops).

@Nexucis

Nexucis commented Nov 12, 2026

Copy link
Copy Markdown
Member

Hi @ToniAdreal thank you for your contribution ! Can you solve the conflict please ?

If Schedule.Next returns the zero time after a firing (e.g. a leap-day
schedule whose next match is more than five years away because 2100 is
not a leap year), arming a timer with a negative duration executes the
task in a busy loop. Log an error and stop the runner instead.

Adds TestCron_StopsWhenNoNextExecutionDate, which builds the runner
directly with a never-matching schedule (NewCron rejects it) and asserts
the task never executes, the runner stops promptly, and an error is
logged.

Assisted-by: Muse Spark:1.3
Signed-off-by: ToniAdreal <184365500+ToniAdreal@users.noreply.github.com>

@Nexucis Nexucis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome ! Thank you @ToniAdreal

@Nexucis
Nexucis merged commit a0137d5 into perses:main Nov 12, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants