From d6457ee48595a392f74f41eb66768497be9f0014 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 11 Nov 2021 16:54:36 +0300 Subject: [PATCH] [#922] shard: Allow multiple gc.stop() calls Use `sync.Once` to prevent locks of stopping GC. It will also allow to safely call `Shard.Close` multiple times. Signed-off-by: Leonard Lyubich --- pkg/local_object_storage/shard/gc.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/local_object_storage/shard/gc.go b/pkg/local_object_storage/shard/gc.go index f1c832f89..4a3666a76 100644 --- a/pkg/local_object_storage/shard/gc.go +++ b/pkg/local_object_storage/shard/gc.go @@ -52,6 +52,7 @@ type eventHandlers struct { type gc struct { *gcCfg + onceStop sync.Once stopChannel chan struct{} workerPool util.WorkerPool @@ -163,7 +164,9 @@ func (gc *gc) tickRemover() { } func (gc *gc) stop() { - gc.stopChannel <- struct{}{} + gc.onceStop.Do(func() { + gc.stopChannel <- struct{}{} + }) } // iterates over metabase graveyard and deletes objects