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

fix: prevent goroutine leak on workload identity reconciliation #1902

Merged
merged 1 commit into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/provider/gcp/secretmanager/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func NewTokenSource(ctx context.Context, auth esv1beta1.GCPSMAuth, projectID str
useMu.Unlock()
return nil, fmt.Errorf("unable to initialize workload identity")
}
defer wi.Close()
ts, err = wi.TokenSource(ctx, auth, isClusterKind, kube, namespace)
if ts != nil || err != nil {
return ts, err
Expand Down
4 changes: 2 additions & 2 deletions pkg/provider/gcp/secretmanager/workload_identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ type saTokenGenerator interface {
}

func newWorkloadIdentity(ctx context.Context, projectID string) (*workloadIdentity, error) {
iamc, err := newIAMClient(ctx)
satg, err := newSATokenGenerator()
if err != nil {
return nil, err
}
satg, err := newSATokenGenerator()
iamc, err := newIAMClient(ctx)
Copy link
Contributor Author

@tapih tapih Jan 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following change also works, but I took the different approach that just changes the order of newSATokenGenerator and newIAMClient for simplicity.

	iamc, err := newIAMClient(ctx)
	if err != nil {
		return nil, err
	}
	satg, err := newSATokenGenerator()
	if err != nil {
		iamc.Close()
		return nil, err
	}

if err != nil {
return nil, err
}
Expand Down