Skip to content

Commit

Permalink
Merge pull request kubernetes#96777 from lianghao208/patch-1
Browse files Browse the repository at this point in the history
fix: concurrent map writes error in VolumeBinding plugin during Filter
  • Loading branch information
k8s-ci-robot authored Nov 23, 2020
2 parents 7566c9b + 42c00bc commit 7335824
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"errors"
"fmt"
"sync"
"time"

v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -53,6 +54,7 @@ type stateData struct {
// phase for each node
// it's initialized in the PreFilter phase
podVolumesByNode map[string]*scheduling.PodVolumes
sync.Mutex
}

func (d *stateData) Clone() framework.StateData {
Expand Down Expand Up @@ -205,9 +207,10 @@ func (pl *VolumeBinding) Filter(ctx context.Context, cs *framework.CycleState, p
return status
}

cs.Lock()
// multiple goroutines call `Filter` on different nodes simultaneously and the `CycleState` may be duplicated, so we must use a local lock here
state.Lock()
state.podVolumesByNode[node.Name] = podVolumes
cs.Unlock()
state.Unlock()
return nil
}

Expand Down

0 comments on commit 7335824

Please sign in to comment.