From 6f4aa66d2629fd2d37c46de6764078cfd03d3a17 Mon Sep 17 00:00:00 2001 From: Devan Date: Thu, 17 Oct 2024 15:56:19 -0500 Subject: [PATCH] fix: add mutex --- tsdb/store.go | 3 +++ tsdb/store_test.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tsdb/store.go b/tsdb/store.go index 3c1852d2628..32e426222d3 100644 --- a/tsdb/store.go +++ b/tsdb/store.go @@ -678,6 +678,9 @@ func (s *Store) Shard(id uint64) *Shard { // longer in a "bad" state. This method will return any shards that // were removed from the cache. func (s *Store) ClearBadShardList() map[uint64]error { + s.mu.Lock() + defer s.mu.Unlock() + badShards := s.GetBadShardList() clear(s.badShards.shardErrors) diff --git a/tsdb/store_test.go b/tsdb/store_test.go index ff5cd26b459..311b2336f2b 100644 --- a/tsdb/store_test.go +++ b/tsdb/store_test.go @@ -282,7 +282,7 @@ func TestStore_BadShardClear(t *testing.T) { require.ErrorIs(t, err2, tsdb.ErrPreviousShardFail{}) require.EqualError(t, err2, fmt.Errorf("not attempting to open shard %d; opening shard previously failed with: %w", shId, expErr).Error()) - require.Equal(t, 1, len(s.Store.GetBadShardList())) + require.Len(t, s.Store.GetBadShardList(), 1) badShards := s.ClearBadShardList() require.Len(t, badShards, 1)