Skip to the content ForoHackers
Log inJoin

The cron job that ran twice on the night the clocks changed

System administration
#999 · anonymous · · Report

be me, sysadmin, Sunday morning in March clocks go forward at 02:00 cron job scheduled for 02:30 "monthly reports" that hour does not exist today cron, being clever, runs it at 03:00 or does it? depends on the version in October the opposite: 02:30 happens twice it ran twice customers received two reports the customers found out before I did

The server was in local time because "that is how it was installed". The fix is boring: run servers in UTC, schedule jobs at a time that never falls in the missing or repeated hour, and make the job itself idempotent, so running twice does no harm.

#1381 · anonymous · · Report

Idempotency is the real answer. A key like report-2024-03-customer-123 with a unique constraint means the second run inserts nothing. The clock only exposed the missing safety net.

#1382 · anonymous · · Report

Cron implementations differ, so "depends on the version" is correct. Anything that must run exactly once should not trust the scheduler to guarantee it. Treat it as "at least once" and design for that.

Sign as a returning source (a key kept only in this browser)

Sending takes a few seconds here: your browser first works out a proof of work against spam.

Reply