Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor change to use cancel context.
Browse files Browse the repository at this point in the history
Joerger committed Oct 16, 2024
1 parent 65608ac commit 979a399
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/services/local/users.go
Original file line number Diff line number Diff line change
@@ -1381,6 +1381,8 @@ func (s *IdentityService) GetMFADevices(ctx context.Context, user string, withSe

// get normal MFA devices and SSO mfa device concurrently, returning the first error we get.
errC := make(chan error)
ctx, cancel := context.WithCancel(ctx)
defer cancel()

var devices []*types.MFADevice
go func() {
@@ -1402,11 +1404,14 @@ func (s *IdentityService) GetMFADevices(ctx context.Context, user string, withSe

var errs []error
for i := 0; i < 2; i++ {
errs = append(errs, <-errC)
if err := <-errC; err != nil {
errs = append(errs, err)
cancel()
}
}

if err := trace.NewAggregate(errs...); err != nil {
return nil, trace.Wrap(err)
if len(errs) != 0 {
return nil, trace.NewAggregate(errs...)
}

if ssoDev != nil {

0 comments on commit 979a399

Please sign in to comment.