From 44bf36ff6d193217d08c77e29ee3f42470ab4b86 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sat, 5 Dec 2026 06:35:12 -0800 Subject: [PATCH] seaweed-block: the observation host reads the store clock under its lock The rebuild loop read the store's clock source without the store lock while SetNowForTest swaps it under that lock, so a test that swaps the clock on a running host raced the loop arming its deadline timer. Co-Authored-By: Claude Opus 5.5 --- seaweed-block/core/authority/observation_host.go | 2 +- seaweed-block/core/authority/observation_store.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/seaweed-block/core/authority/observation_host.go b/seaweed-block/core/authority/observation_host.go index d1d851bbe7..853ed643db 100644 --- a/seaweed-block/core/authority/observation_host.go +++ b/seaweed-block/core/authority/observation_host.go @@ -258,7 +258,7 @@ func (h *ObservationHost) run(ctx context.Context) { var deadlineC <-chan time.Time var timer *time.Timer if at := h.store.NextDeadline(); !at.IsZero() { - d := at.Sub(h.store.now()) + d := at.Sub(h.store.clock()) if d < 10*time.Millisecond { d = 10 * time.Millisecond } diff --git a/seaweed-block/core/authority/observation_store.go b/seaweed-block/core/authority/observation_store.go index 7be900c3ee..00f6d4ab5d 100644 --- a/seaweed-block/core/authority/observation_store.go +++ b/seaweed-block/core/authority/observation_store.go @@ -285,6 +285,14 @@ func (s *ObservationStore) SetNowForTest(now func() time.Time) { s.now = now } +// clock reads the time from the clock source SetNowForTest may swap. +func (s *ObservationStore) clock() time.Time { + s.mu.Lock() + now := s.now + s.mu.Unlock() + return now() +} + // NewObservationStore constructs a store with the given freshness // configuration. `now` is injected for deterministic testing; pass // time.Now in production.