Skip to content

Commit

Permalink
nfd-master: protect node updater pool queueing with a lock
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
marquiz committed Mar 27, 2024
1 parent 137f18b commit bce446c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pkg/nfd-master/nfd-master.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ func (m *nfdMaster) nfdAPIUpdateHandler() {
}
} else {
for nodeName := range updateNodes {
m.nodeUpdaterPool.queue.Add(nodeName)
m.nodeUpdaterPool.addNode(nodeName)

Check warning on line 445 in pkg/nfd-master/nfd-master.go

View check run for this annotation

Codecov / codecov/patch

pkg/nfd-master/nfd-master.go#L445

Added line #L445 was not covered by tests
}
}

Expand Down Expand Up @@ -710,7 +710,7 @@ func (m *nfdMaster) nfdAPIUpdateAllNodes() error {
}

for _, node := range nodes.Items {
m.nodeUpdaterPool.queue.Add(node.Name)
m.nodeUpdaterPool.addNode(node.Name)

Check warning on line 713 in pkg/nfd-master/nfd-master.go

View check run for this annotation

Codecov / codecov/patch

pkg/nfd-master/nfd-master.go#L713

Added line #L713 was not covered by tests
}

return nil
Expand Down
8 changes: 7 additions & 1 deletion pkg/nfd-master/node-updater-pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

type nodeUpdaterPool struct {
queue workqueue.RateLimitingInterface
sync.Mutex
sync.RWMutex

wg sync.WaitGroup
nfdMaster *nfdMaster
Expand Down Expand Up @@ -114,3 +114,9 @@ func (u *nodeUpdaterPool) stop() {
u.queue.ShutDown()
u.wg.Wait()
}

func (u *nodeUpdaterPool) addNode(nodeName string) {
u.RLock()
defer u.RUnlock()
u.queue.Add(nodeName)

Check warning on line 121 in pkg/nfd-master/node-updater-pool.go

View check run for this annotation

Codecov / codecov/patch

pkg/nfd-master/node-updater-pool.go#L118-L121

Added lines #L118 - L121 were not covered by tests
}

0 comments on commit bce446c

Please sign in to comment.