From 5ba4bd1373e29a729f6726bd6bf9f7de5a9749f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wenkai=20Yin=28=E5=B0=B9=E6=96=87=E5=BC=80=29?= Date: Wed, 14 May 2025 14:16:45 +0800 Subject: [PATCH] Call WaitGroup.Done() once only when PVB changes to final status the first time to avoid panic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Call WaitGroup.Done() once only when PVB changes to final status the first time to avoid panic Signed-off-by: Wenkai Yin(尹文开) --- pkg/podvolume/backupper.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pkg/podvolume/backupper.go b/pkg/podvolume/backupper.go index d873cc96c..776cdc332 100644 --- a/pkg/podvolume/backupper.go +++ b/pkg/podvolume/backupper.go @@ -173,11 +173,28 @@ func newBackupper( return } + statusChangedToFinal := true + existObj, exist, err := b.pvbIndexer.Get(pvb) + if err == nil && exist { + existPVB, ok := existObj.(*velerov1api.PodVolumeBackup) + // the PVB in the indexer is already in final status, no need to call WaitGroup.Done() + if ok && (existPVB.Status.Phase == velerov1api.PodVolumeBackupPhaseCompleted || + existPVB.Status.Phase == velerov1api.PodVolumeBackupPhaseFailed) { + statusChangedToFinal = false + } + } + // the Indexer inserts PVB directly if the PVB to be updated doesn't exist if err := b.pvbIndexer.Update(pvb); err != nil { log.WithError(err).Errorf("failed to update PVB %s/%s in indexer", pvb.Namespace, pvb.Name) } - b.wg.Done() + + // call WaitGroup.Done() once only when the PVB changes to final status the first time. + // This avoid the cases that the handler gets multiple update events whose PVBs are all in final status + // which causes panic with "negative WaitGroup counter" error + if statusChangedToFinal { + b.wg.Done() + } }, }, )