bimapper: fix data race (#18519)

This commit is contained in:
Iryna Shustava 2023-08-18 07:55:12 -06:00 committed by GitHub
parent cc596ce772
commit 0b580ffd22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -272,7 +272,10 @@ func (m *Mapper) MapLink(_ context.Context, _ controller.Runtime, res *pbresourc
} }
func (m *Mapper) itemIDsByLink(link resource.ReferenceKey) []*pbresource.ID { func (m *Mapper) itemIDsByLink(link resource.ReferenceKey) []*pbresource.ID {
items, ok := m.getItemsByLink(link) m.lock.Lock()
defer m.lock.Unlock()
items, ok := m.linkToItem[link]
if !ok { if !ok {
return nil return nil
} }
@ -285,7 +288,10 @@ func (m *Mapper) itemIDsByLink(link resource.ReferenceKey) []*pbresource.ID {
} }
func (m *Mapper) itemRefsByLink(link resource.ReferenceKey) []*pbresource.Reference { func (m *Mapper) itemRefsByLink(link resource.ReferenceKey) []*pbresource.Reference {
items, ok := m.getItemsByLink(link) m.lock.Lock()
defer m.lock.Unlock()
items, ok := m.linkToItem[link]
if !ok { if !ok {
return nil return nil
} }
@ -296,11 +302,3 @@ func (m *Mapper) itemRefsByLink(link resource.ReferenceKey) []*pbresource.Refere
} }
return out return out
} }
func (m *Mapper) getItemsByLink(link resource.ReferenceKey) (map[resource.ReferenceKey]struct{}, bool) {
m.lock.Lock()
defer m.lock.Unlock()
items, ok := m.linkToItem[link]
return items, ok
}