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 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 committed 2026-12-05 06:35:12 -08:00
1 parent acc22a4270
commit 44bf36ff6d
2 files changed
+9 -1

No files matched your search

@@ -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
}
@@ -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.