[#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 <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-11-11 16:54:36 +03:00 committed by Alex Vanin
parent 10f0bd91d6
commit d6457ee485

View file

@ -52,6 +52,7 @@ type eventHandlers struct {
type gc struct { type gc struct {
*gcCfg *gcCfg
onceStop sync.Once
stopChannel chan struct{} stopChannel chan struct{}
workerPool util.WorkerPool workerPool util.WorkerPool
@ -163,7 +164,9 @@ func (gc *gc) tickRemover() {
} }
func (gc *gc) stop() { func (gc *gc) stop() {
gc.stopChannel <- struct{}{} gc.onceStop.Do(func() {
gc.stopChannel <- struct{}{}
})
} }
// iterates over metabase graveyard and deletes objects // iterates over metabase graveyard and deletes objects