Skip to content

Commit 715ed4b

Browse files
sagor999roboquat
authored andcommitted
fix race condition when creating notifyPod channel
1 parent da14b24 commit 715ed4b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

components/ws-manager/pkg/manager/monitor.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ type Monitor struct {
8686

8787
OnError func(error)
8888

89-
notifyPod map[string]chan string
89+
notifyPod map[string]chan string
90+
notifyPodMapLock sync.Mutex
9091

9192
eventRecorder record.EventRecorder
9293
}
@@ -201,9 +202,11 @@ func (m *Monitor) onVolumesnapshotEvent(evt watch.Event) error {
201202
m.eventRecorder.Eventf(&pod, corev1.EventTypeNormal, "VolumeSnapshot", "Volume snapshot %q is ready to use", vs.Name)
202203
}
203204

205+
m.notifyPodMapLock.Lock()
204206
if m.notifyPod[podName] == nil {
205207
m.notifyPod[podName] = make(chan string)
206208
}
209+
m.notifyPodMapLock.Unlock()
207210
m.notifyPod[podName] <- vsc
208211

209212
return nil
@@ -1154,9 +1157,11 @@ func (m *Monitor) finalizeWorkspaceContent(ctx context.Context, wso *workspaceOb
11541157
volumeSnapshotTime = time.Now()
11551158
}
11561159
if createdVolumeSnapshot {
1160+
m.notifyPodMapLock.Lock()
11571161
if m.notifyPod[wso.Pod.Name] == nil {
11581162
m.notifyPod[wso.Pod.Name] = make(chan string)
11591163
}
1164+
m.notifyPodMapLock.Unlock()
11601165

11611166
select {
11621167
case pvcVolumeSnapshotContentName = <-m.notifyPod[wso.Pod.Name]:

0 commit comments

Comments
 (0)