Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bimapper: fix data race #18519

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}