From 1118b285d3d591647aa694b5b97b110de212bb7f Mon Sep 17 00:00:00 2001 From: Praveen raj Mani Date: Wed, 14 Feb 2024 21:37:44 +0530 Subject: [PATCH] fix: race in deleting objects during batch expiry (#19054) --- cmd/batch-expire.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/batch-expire.go b/cmd/batch-expire.go index 72bc48330..b454f4744 100644 --- a/cmd/batch-expire.go +++ b/cmd/batch-expire.go @@ -572,7 +572,11 @@ func (r *BatchJobExpire) Start(ctx context.Context, api ObjectLayer, job BatchJo }() expireCh := make(chan []expireObjInfo, workerSize) - go batchObjsForDelete(ctx, r, ri, job, api, wk, expireCh) + expireDoneCh := make(chan struct{}) + go func() { + defer close(expireDoneCh) + batchObjsForDelete(ctx, r, ri, job, api, wk, expireCh) + }() var ( prevObj ObjectInfo @@ -651,7 +655,8 @@ func (r *BatchJobExpire) Start(ctx context.Context, api ObjectLayer, job BatchJo } xioutil.SafeClose(expireCh) - wk.Wait() // waits for all expire goroutines to complete + <-expireDoneCh // waits for the expire goroutine to complete + wk.Wait() // waits for all expire workers to retire ri.Complete = ri.ObjectsFailed == 0 ri.Failed = ri.ObjectsFailed > 0