Skip to content

Commit

Permalink
bimapper: fix data race (#18519)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishustava authored Aug 18, 2023
1 parent cc596ce commit 0b580ff
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions internal/resource/mappers/bimapper/bimapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,10 @@ func (m *Mapper) MapLink(_ context.Context, _ controller.Runtime, res *pbresourc
}

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 {
return nil
}
Expand All @@ -285,7 +288,10 @@ func (m *Mapper) itemIDsByLink(link resource.ReferenceKey) []*pbresource.ID {
}

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 {
return nil
}
Expand All @@ -296,11 +302,3 @@ func (m *Mapper) itemRefsByLink(link resource.ReferenceKey) []*pbresource.Refere
}
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
}

0 comments on commit 0b580ff

Please sign in to comment.