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

Reuse Token for serviceAccount credentials #1238

Merged
merged 2 commits into from
May 16, 2017
Merged

Reuse Token for serviceAccount credentials #1238

merged 2 commits into from
May 16, 2017

Conversation

dfawley
Copy link
Member

@dfawley dfawley commented May 12, 2017

jwt.Config.TokenSource returns a reusable TokenSource; we should re-use it to avoid sending a new request every time we need to use the token.

@dfawley dfawley requested a review from menghanl May 12, 2017 19:45
func (s serviceAccount) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
token, err := s.config.TokenSource(ctx).Token()
func (s *serviceAccount) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
s.once.Do(func() { s.ts = s.config.TokenSource(ctx) })
Copy link
Contributor

Choose a reason for hiding this comment

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

This means that ctx will continue to be used even after it has been cancelled by the caller. Doesn't seem bueno.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, thanks. I changed it to cache the token internally and fetch a new one when necessary.

@dfawley dfawley merged commit 3419b42 into grpc:master May 16, 2017
@dfawley dfawley changed the title Reuse TokenSource Reuse Token for serviceAccount credentials May 16, 2017
@dfawley dfawley deleted the ts branch July 25, 2017 17:23
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants