1.5 KiB
| id | type | title | tags | importance | confidence | created | updated | relations | |||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| b33e2316-6313-4ed9-b95a-3a469b820101 | insight | Systemd OnCalendar=weekly and OnCalendar=daily fire simultaneously on Sundays/Mondays - always stagger shared-state timers |
|
0.5 | 0.8 | 2026-02-20T06:47:13.739265+00:00 | 2026-02-20T06:47:17.701728+00:00 |
|
Systemd Timer Collision Gotcha
The Problem
OnCalendar=weekly resolves to Mon *-*-* 00:00:00 (Monday midnight). If another timer uses OnCalendar=daily, both fire at the same second on Monday midnight. Any two services that share a state file will race each other.
Consequence
Silent data loss. If both services do read-modify-write on the same JSON file without atomic locking, one will clobber the other's changes. If the loser's write also corrupts the file, a silent JSONDecodeError catch can return an empty dict, permanently losing all state.
Fix Pattern
Always stagger timers that access shared resources by at least an hour:
# Instead of:
OnCalendar=weekly
# Use:
OnCalendar=Sun *-*-* 02:00:00
This avoids the Monday midnight collision and gives the daily timer time to finish first.
General Rule
Never schedule two services that share state files at the same OnCalendar interval without explicit offset staggering.