Skip to content

Commit

Permalink
fix potential race in query children. Map can be accessed concurrently
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanl committed Mar 11, 2019
1 parent 21a80ad commit 9e3bafc
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions internal/queryer/queryer.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ func New(c cache.Cache, discoveryClient discovery.DiscoveryInterface) *CacheQuer
}

func (cq *CacheQueryer) Children(ctx context.Context, owner metav1.Object) ([]kruntime.Object, error) {
cq.mu.Lock()
defer cq.mu.Unlock()

if owner == nil {
return nil, errors.New("owner is nil")
}
Expand All @@ -74,6 +77,7 @@ func (cq *CacheQueryer) Children(ctx context.Context, owner metav1.Object) ([]kr
defer span.End()

cached, ok := cq.children[owner.GetUID()]

if ok {
return cached, nil
}
Expand Down Expand Up @@ -143,9 +147,7 @@ func (cq *CacheQueryer) Children(ctx context.Context, owner metav1.Object) ([]kr

close(ch)

cq.mu.Lock()
cq.children[owner.GetUID()] = children
cq.mu.Unlock()

return children, nil
}
Expand Down

0 comments on commit 9e3bafc

Please sign in to comment.