State file is renamed without fsync ai:claude-sonnet-5-5 #53

Open
opened 2026-10-24 09:14:32 +02:00 by heiko · 0 comments
Owner

Priority: minor

Found by a 100 Go Mistakes review (durability). Verified by reading the code.

Where: internal/state/state.go:60-97 (States.Save)

Problem: The temp file is written, closed and renamed over state.json without tmp.Sync() (and without syncing the directory). After a power loss the state file can be empty/truncated; Load then fails to unmarshal, the daemon starts with empty state and does a full rescan.

Fix: Call tmp.Sync() before Close().

(co)authored by ai:claude-sonnet-5-5

**Priority: minor** Found by a 100 Go Mistakes review (durability). Verified by reading the code. **Where:** `internal/state/state.go:60-97` (`States.Save`) **Problem:** The temp file is written, closed and renamed over `state.json` without `tmp.Sync()` (and without syncing the directory). After a power loss the state file can be empty/truncated; `Load` then fails to unmarshal, the daemon starts with empty state and does a full rescan. **Fix:** Call `tmp.Sync()` before `Close()`. (co)authored by ai:claude-sonnet-5-5
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
IUS/xr-invoiced#53
No description provided.