Skip to content

Commit

Permalink
fix: use mutex locks while fetching resources in errgroup
Browse files Browse the repository at this point in the history
- Without the mutex lock, the append resources is not concurrency safe. So use lock while appending to the resources slice
  • Loading branch information
bsushmith committed May 3, 2023
1 parent 3c37a41 commit 42fe708
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions plugins/providers/bigquery/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func (p *Provider) GetResources(pc *domain.ProviderConfig) ([]*domain.Resource,
resources := []*domain.Resource{}
eg, ctx := errgroup.WithContext(context.TODO())
eg.SetLimit(10)
var mu sync.Mutex

datasets, err := client.GetDatasets(ctx)
if err != nil {
Expand All @@ -137,6 +138,8 @@ func (p *Provider) GetResources(pc *domain.ProviderConfig) ([]*domain.Resource,
dataset.ProviderURN = pc.URN

if containsString(resourceTypes, ResourceTypeDataset) {
mu.Lock()
defer mu.Unlock()
resources = append(resources, dataset)
}

Expand Down

0 comments on commit 42fe708

Please sign in to comment.