diff --git a/CHANGELOG.md b/CHANGELOG.md index 81c0712ac..ae617c427 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ Changelog for NeoFS Node - Correctly sign new epoch transaction in neofs-adm for a committee of more than 4 nodes (#1949) - Inability to provide session to NeoFS CLI in a NeoFS-binary format (#1933) - `neofs-adm` now works correctly with a committee of more than 4 nodes (#1949, #1959) +- Closing a shard now waits until GC background workers stop (#1964) ### Removed ### Updated diff --git a/pkg/local_object_storage/shard/gc.go b/pkg/local_object_storage/shard/gc.go index 75db47cf4..95a7ddba2 100644 --- a/pkg/local_object_storage/shard/gc.go +++ b/pkg/local_object_storage/shard/gc.go @@ -65,6 +65,7 @@ type gc struct { onceStop sync.Once stopChannel chan struct{} + wg sync.WaitGroup workerPool util.WorkerPool @@ -103,11 +104,14 @@ func (gc *gc) init() { gc.workerPool = gc.workerPoolInit(sz) } + gc.wg.Add(2) go gc.tickRemover() go gc.listenEvents() } func (gc *gc) listenEvents() { + defer gc.wg.Done() + for { event, ok := <-gc.eventChan if !ok { @@ -147,6 +151,8 @@ func (gc *gc) listenEvents() { } func (gc *gc) tickRemover() { + defer gc.wg.Done() + timer := time.NewTimer(gc.removerInterval) defer timer.Stop() @@ -172,6 +178,9 @@ func (gc *gc) stop() { gc.onceStop.Do(func() { gc.stopChannel <- struct{}{} }) + + gc.log.Info("waiting for GC workers to stop...") + gc.wg.Wait() } // iterates over metabase and deletes objects