Skip to content

Commit

Permalink
fix: eliminate goroutine leak in the authenticators (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
pyrooka authored Apr 22, 2021
1 parent c795ac6 commit e5d921a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
13 changes: 2 additions & 11 deletions v5/core/cp4d_authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,8 @@ func (authenticator *CloudPakForDataAuthenticator) getToken() (string, error) {
}
} else if authenticator.getTokenData().needsRefresh() {
// If refresh needed, kick off a go routine in the background to get a new token
ch := make(chan error)
go func() {
ch <- authenticator.invokeRequestTokenData()
}()
select {
case err := <-ch:
if err != nil {
return "", err
}
default:
}
//nolint: errcheck
go authenticator.invokeRequestTokenData()
}

// return an error if the access token is not valid or was not fetched
Expand Down
13 changes: 2 additions & 11 deletions v5/core/iam_authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,8 @@ func (authenticator *IamAuthenticator) getToken() (string, error) {
}
} else if authenticator.getTokenData().needsRefresh() {
// If refresh needed, kick off a go routine in the background to get a new token
ch := make(chan error)
go func() {
ch <- authenticator.invokeRequestTokenData()
}()
select {
case err := <-ch:
if err != nil {
return "", err
}
default:
}
//nolint: errcheck
go authenticator.invokeRequestTokenData()
}

// return an error if the access token is not valid or was not fetched
Expand Down

0 comments on commit e5d921a

Please sign in to comment.