Skip to content

Commit

Permalink
fix: data race
Browse files Browse the repository at this point in the history
  • Loading branch information
Tochemey committed Jul 9, 2023
1 parent 088f99d commit aa58343
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions discovery/kubernetes/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@ func (d *Discovery) handlePodAdded(pod *corev1.Pod) {

// handlePodUpdated is called when a pod is updated
func (d *Discovery) handlePodUpdated(old *corev1.Pod, pod *corev1.Pod) {
// acquire the lock
d.mu.Lock()
// release the lock
defer d.mu.Unlock()

// first check whether the discovery provider is running
if !d.isInitialized.Load() {
return
Expand All @@ -280,10 +285,6 @@ func (d *Discovery) handlePodUpdated(old *corev1.Pod, pod *corev1.Pod) {
return
}

// acquire the lock
d.mu.Lock()
// release the lock
defer d.mu.Unlock()
// grab the old node
oldNode := d.podToNode(old)
// get the new node
Expand Down

0 comments on commit aa58343

Please sign in to comment.