Skip to content

Commit bce446c

Browse files
committed
nfd-master: protect node updater pool queueing with a lock
Prevents races when (re-)starting the queue. There are no reports on issues related to this (and I haven't come up with any actual failure path in the current code) but better to be safe and follow the best practices.
1 parent 137f18b commit bce446c

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

pkg/nfd-master/nfd-master.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ func (m *nfdMaster) nfdAPIUpdateHandler() {
442442
}
443443
} else {
444444
for nodeName := range updateNodes {
445-
m.nodeUpdaterPool.queue.Add(nodeName)
445+
m.nodeUpdaterPool.addNode(nodeName)
446446
}
447447
}
448448

@@ -710,7 +710,7 @@ func (m *nfdMaster) nfdAPIUpdateAllNodes() error {
710710
}
711711

712712
for _, node := range nodes.Items {
713-
m.nodeUpdaterPool.queue.Add(node.Name)
713+
m.nodeUpdaterPool.addNode(node.Name)
714714
}
715715

716716
return nil

pkg/nfd-master/node-updater-pool.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828

2929
type nodeUpdaterPool struct {
3030
queue workqueue.RateLimitingInterface
31-
sync.Mutex
31+
sync.RWMutex
3232

3333
wg sync.WaitGroup
3434
nfdMaster *nfdMaster
@@ -114,3 +114,9 @@ func (u *nodeUpdaterPool) stop() {
114114
u.queue.ShutDown()
115115
u.wg.Wait()
116116
}
117+
118+
func (u *nodeUpdaterPool) addNode(nodeName string) {
119+
u.RLock()
120+
defer u.RUnlock()
121+
u.queue.Add(nodeName)
122+
}

0 commit comments

Comments
 (0)