Skip to content

Commit 13093b2

Browse files
committed
Call WaitGroup.Done() once only when PVB changes to final status the first time to avoid panic
Prevents calling WaitGroup.Done() multiple times for the same PodVolumeBackup by tracking processed PVBs. This avoids "negative WaitGroup counter" panic errors when the handler receives multiple update events with the PVB already in final status. Based on upstream commit 2eb97fa Adapted for OADP 1.4 without pvbIndexer infrastructure Signed-off-by: Tiger Kaovilai <tkaovilai@redhat.com>
1 parent c11c570 commit 13093b2

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

pkg/podvolume/backupper.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type backupper struct {
5858
handlerRegistration cache.ResourceEventHandlerRegistration
5959
wg sync.WaitGroup
6060
result []*velerov1api.PodVolumeBackup
61+
processedPVBs sync.Map // tracks PVBs that have already been processed to avoid calling Done() multiple times
6162
}
6263

6364
type skippedPVC struct {
@@ -109,14 +110,15 @@ func newBackupper(
109110
backup *velerov1api.Backup,
110111
) *backupper {
111112
b := &backupper{
112-
ctx: ctx,
113-
repoLocker: repoLocker,
114-
repoEnsurer: repoEnsurer,
115-
crClient: crClient,
116-
uploaderType: uploaderType,
117-
pvbInformer: pvbInformer,
118-
wg: sync.WaitGroup{},
119-
result: []*velerov1api.PodVolumeBackup{},
113+
ctx: ctx,
114+
repoLocker: repoLocker,
115+
repoEnsurer: repoEnsurer,
116+
crClient: crClient,
117+
uploaderType: uploaderType,
118+
pvbInformer: pvbInformer,
119+
wg: sync.WaitGroup{},
120+
result: []*velerov1api.PodVolumeBackup{},
121+
processedPVBs: sync.Map{},
120122
}
121123

122124
b.handlerRegistration, _ = pvbInformer.AddEventHandler(
@@ -133,8 +135,16 @@ func newBackupper(
133135
return
134136
}
135137

136-
b.result = append(b.result, pvb)
137-
b.wg.Done()
138+
// Generate a unique key for this PVB
139+
pvbKey := pvb.Namespace + "/" + pvb.Name
140+
141+
// Check if we've already processed this PVB in final status
142+
// This prevents calling WaitGroup.Done() multiple times for the same PVB
143+
// which could happen if the handler receives multiple update events with the PVB already in final status
144+
if _, alreadyProcessed := b.processedPVBs.LoadOrStore(pvbKey, true); !alreadyProcessed {
145+
b.result = append(b.result, pvb)
146+
b.wg.Done()
147+
}
138148
},
139149
},
140150
)

0 commit comments

Comments
 (0)