From e53d2032fe5a13dc682caa77e4a8c9cdf06ba4a2 Mon Sep 17 00:00:00 2001 From: Sandeep Sukhani Date: Thu, 10 Sep 2020 17:21:22 +0530 Subject: [PATCH] fix a panic when trying to stop boltdb-shipper multiple times using sync.once (#2613) --- pkg/storage/store_test.go | 2 ++ pkg/storage/stores/shipper/shipper_index_client.go | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/storage/store_test.go b/pkg/storage/store_test.go index 816ace012e51..e346806d7483 100644 --- a/pkg/storage/store_test.go +++ b/pkg/storage/store_test.go @@ -782,6 +782,8 @@ func TestStore_MultipleBoltDBShippersInConfig(t *testing.T) { }}, limits, nil) require.NoError(t, err) + defer store.Stop() + // time ranges adding a chunk for each store and a chunk which overlaps both the stores chunksToBuildForTimeRanges := []timeRange{ { diff --git a/pkg/storage/stores/shipper/shipper_index_client.go b/pkg/storage/stores/shipper/shipper_index_client.go index a3444a67b948..647f7866b340 100644 --- a/pkg/storage/stores/shipper/shipper_index_client.go +++ b/pkg/storage/stores/shipper/shipper_index_client.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "os" "path" + "sync" "time" "github.com/cortexproject/cortex/pkg/chunk" @@ -76,7 +77,8 @@ type Shipper struct { uploadsManager *uploads.TableManager downloadsManager *downloads.TableManager - metrics *metrics + metrics *metrics + stopOnce sync.Once } // NewShipper creates a shipper for syncing local objects with a store @@ -179,6 +181,10 @@ func (s *Shipper) getUploaderName() (string, error) { } func (s *Shipper) Stop() { + s.stopOnce.Do(s.stop) +} + +func (s *Shipper) stop() { if s.uploadsManager != nil { s.uploadsManager.Stop() }