Skip to content

Commit 2eb97fa

Browse files
authored
Merge pull request vmware-tanzu#8940 from ywk253100/250514_fix
Call WaitGroup.Done() once only when PVB changes to fianl status the first time to avoid panic
2 parents 4bd86f1 + f64fb36 commit 2eb97fa

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

changelogs/CHANGELOG-1.16.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ https://velero.io/docs/v1.16/
1313
https://velero.io/docs/v1.16/upgrade-to-1.16/
1414

1515
### All Changes
16+
* Call WaitGroup.Done() once only when PVB changes to final status the first time to avoid panic (#8940, @ywk253100)
1617
* Add VolumeSnapshotContent into the RIA and the mustHave resource list. (#8926, @blackpiglet)
1718
* Warn for not found error in patching managed fields (#8916, @sseago)
1819
* Fix issue 8878, relief node os deduction error checks (#8911, @Lyndon-Li)

pkg/podvolume/backupper.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,28 @@ func newBackupper(
173173
return
174174
}
175175

176+
statusChangedToFinal := true
177+
existObj, exist, err := b.pvbIndexer.Get(pvb)
178+
if err == nil && exist {
179+
existPVB, ok := existObj.(*velerov1api.PodVolumeBackup)
180+
// the PVB in the indexer is already in final status, no need to call WaitGroup.Done()
181+
if ok && (existPVB.Status.Phase == velerov1api.PodVolumeBackupPhaseCompleted ||
182+
existPVB.Status.Phase == velerov1api.PodVolumeBackupPhaseFailed) {
183+
statusChangedToFinal = false
184+
}
185+
}
186+
176187
// the Indexer inserts PVB directly if the PVB to be updated doesn't exist
177188
if err := b.pvbIndexer.Update(pvb); err != nil {
178189
log.WithError(err).Errorf("failed to update PVB %s/%s in indexer", pvb.Namespace, pvb.Name)
179190
}
180-
b.wg.Done()
191+
192+
// call WaitGroup.Done() once only when the PVB changes to final status the first time.
193+
// This avoid the cases that the handler gets multiple update events whose PVBs are all in final status
194+
// which causes panic with "negative WaitGroup counter" error
195+
if statusChangedToFinal {
196+
b.wg.Done()
197+
}
181198
},
182199
},
183200
)

0 commit comments

Comments
 (0)