store: Systemd OnCalendar=weekly and OnCalendar=daily fire simultaneously on Sundays/Mondays - always stagger shared-state timers

This commit is contained in:
Cal Corum 2026-02-20 00:47:13 -06:00
parent 8002a0f148
commit b2222fb338

View File

@ -0,0 +1,34 @@
---
id: b33e2316-6313-4ed9-b95a-3a469b820101
type: insight
title: "Systemd OnCalendar=weekly and OnCalendar=daily fire simultaneously on Sundays/Mondays - always stagger shared-state timers"
tags: [systemd, timer, gotcha, race-condition, cognitive-memory, scheduling]
importance: 0.5
confidence: 0.8
created: "2026-02-20T06:47:13.739265+00:00"
updated: "2026-02-20T06:47:13.739265+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:
```ini
# 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.