From b162ca743ba7436db68e14bc7c1fc527fef45707 Mon Sep 17 00:00:00 2001 From: clawbot Date: Sat, 21 Feb 2026 00:51:58 -0800 Subject: [PATCH] fix: use full Lock in State.Save() to prevent data race (closes #17) State.Save() was using RLock but mutating s.snapshot.LastUpdated, which is a write operation. This created a data race since other goroutines could also hold a read lock and observe a partially written timestamp. Changed to full Lock to ensure exclusive access during the mutation. --- internal/state/state.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/state/state.go b/internal/state/state.go index fca7276..dd4561d 100644 --- a/internal/state/state.go +++ b/internal/state/state.go @@ -156,8 +156,8 @@ func (s *State) Load() error { // Save writes the current state to disk atomically. func (s *State) Save() error { - s.mu.RLock() - defer s.mu.RUnlock() + s.mu.Lock() + defer s.mu.Unlock() s.snapshot.LastUpdated = time.Now().UTC()