Skip to content

Commit 2360f22

Browse files
committed
add lock for csi node update
Signed-off-by: pacoxu <[email protected]>
1 parent e23d83e commit 2360f22

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pkg/volume/csi/nodeinfomanager/nodeinfomanager.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"fmt"
2626
"math"
2727
"strings"
28+
"sync"
2829

2930
"time"
3031

@@ -66,6 +67,8 @@ type nodeInfoManager struct {
6667
nodeName types.NodeName
6768
volumeHost volume.VolumeHost
6869
migratedPlugins map[string](func() bool)
70+
// lock protects changes to node.
71+
lock sync.Mutex
6972
}
7073

7174
// If no updates is needed, the function must return the same Node object as the input.
@@ -175,6 +178,9 @@ func (nim *nodeInfoManager) updateNode(updateFuncs ...nodeUpdateFunc) error {
175178
// the effects of previous updateFuncs to avoid potential conflicts. For example, if multiple
176179
// functions update the same field, updates in the last function are persisted.
177180
func (nim *nodeInfoManager) tryUpdateNode(updateFuncs ...nodeUpdateFunc) error {
181+
nim.lock.Lock()
182+
defer nim.lock.Unlock()
183+
178184
// Retrieve the latest version of Node before attempting update, so that
179185
// existing changes are not overwritten.
180186

0 commit comments

Comments
 (0)