Skip to content

Commit

Permalink
Add mutex lock to updateServer (linkerd#11169)
Browse files Browse the repository at this point in the history
Fixes linkerd#11163

The `servicePublisher.updateServer` function will iterate through all registered listeners and update them.  However, a nil listener may temporarily be in the list of listeners if an unsubscribe is in progress.  This results in a nil pointer dereference.

All functions which result in updating the listeners must therefore be protected by the mutex so that we don't try to act on the list of listeners while it is being modified.

Signed-off-by: Alex Leong <[email protected]>
  • Loading branch information
adleong authored and jandersen-plaid committed Jul 28, 2023
1 parent 4586ff5 commit 5531b72
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions controller/api/destination/watcher/endpoints_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,9 @@ func (sp *servicePublisher) metricsLabels(port Port, hostname string) prometheus
}

func (sp *servicePublisher) updateServer(server *v1beta1.Server, isAdd bool) {
sp.Lock()
defer sp.Unlock()

selector, err := metav1.LabelSelectorAsSelector(server.Spec.PodSelector)
if err != nil {
sp.log.Errorf("failed to create Selector: %s", err)
Expand Down

0 comments on commit 5531b72

Please sign in to comment.