Skip to content

Commit db3aba2

Browse files
committed
fix: data race in GetGroupsMembersBruteForce concurrent map writes
1 parent 395bad1 commit db3aba2

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

internal/scim/scim.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,12 @@ func (s *Provider) GetGroupsMembersBruteForce(ctx context.Context, gr *model.Gro
508508
// a map of group SCIM IDs to a slice of members
509509
membersByGroup := make(map[string][]*model.Member)
510510

511+
// pre-initialize all map entries before launching goroutines to avoid
512+
// concurrent map writes between the outer loop and goroutine appends
513+
for _, group := range gr.Resources {
514+
membersByGroup[group.SCIMID] = make([]*model.Member, 0, 10)
515+
}
516+
511517
// use an errgroup to manage the goroutines
512518
g, ctx := errgroup.WithContext(ctx)
513519

@@ -520,9 +526,6 @@ func (s *Provider) GetGroupsMembersBruteForce(ctx context.Context, gr *model.Gro
520526
// brute force implemented here thanks to the fxxckin' aws sso scim api
521527
// iterate over each group and user and check if the user is a member of the group
522528
for _, group := range gr.Resources {
523-
// initialize the members slice for the group. Optimistic approach
524-
membersByGroup[group.SCIMID] = make([]*model.Member, 0, 10)
525-
526529
for _, user := range ur.Resources {
527530

528531
// create a new variable for the group and user to avoid data races

0 commit comments

Comments
 (0)