{"action":"created","comment":{"url":"https://api.github.com/repos/grpc/grpc-go/pulls/comments/59151477","id":59151477,"diff_hunk":"@@ -129,11 +129,26 @@ func NewComputeEngine() credentials.Credentials {\n \n // serviceAccount represents credentials via JWT signing key.\n type serviceAccount struct {\n-\tconfig *jwt.Config\n-}\n-\n-func (s serviceAccount) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {\n-\ttoken, err := s.config.TokenSource(ctx).Token()\n+\tconfig      *jwt.Config\n+\ttokenSource oauth2.TokenSource\n+}\n+\n+func (s *serviceAccount) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {\n+\tvar token *oauth2.Token\n+\tvar err error\n+\tif s.tokenSource != nil {\n+\t\ttoken, err = s.tokenSource.Token()\n+\t\tif err != nil {\n+\t\t\ttoken = nil\n+\t\t}\n+\t}\n+\tif token == nil {","path":"credentials/oauth/oauth.go","position":22,"original_position":22,"commit_id":"94e39d128c9bf0fb42ecb1ea411fdacd1ee33b32","original_commit_id":"94e39d128c9bf0fb42ecb1ea411fdacd1ee33b32","user":{"login":"adg","id":8446613,"avatar_url":"https://avatars.githubusercontent.com/u/8446613?v=3","gravatar_id":"","url":"https://api.github.com/users/adg","html_url":"https://github.com/adg","followers_url":"https://api.github.com/users/adg/followers","following_url":"https://api.github.com/users/adg/following{/other_user}","gists_url":"https://api.github.com/users/adg/gists{/gist_id}","starred_url":"https://api.github.com/users/adg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adg/subscriptions","organizations_url":"https://api.github.com/users/adg/orgs","repos_url":"https://api.github.com/users/adg/repos","events_url":"https://api.github.com/users/adg/events{/privacy}","received_events_url":"https://api.github.com/users/adg/received_events","type":"User","site_admin":false},"body":"```\r\nif token == nil || err != nil {\r\n```\r\n\r\nseems clearer.","created_at":"2016-04-11T03:41:27Z","updated_at":"2016-04-11T03:41:27Z","html_url":"https://github.com/grpc/grpc-go/pull/600#discussion_r59151477","pull_request_url":"https://api.github.com/repos/grpc/grpc-go/pulls/600","_links":{"self":{"href":"https://api.github.com/repos/grpc/grpc-go/pulls/comments/59151477"},"html":{"href":"https://github.com/grpc/grpc-go/pull/600#discussion_r59151477"},"pull_request":{"href":"https://api.github.com/repos/grpc/grpc-go/pulls/600"}}},"pull_request":{"url":"https://api.github.com/repos/grpc/grpc-go/pulls/600","id":63809930,"html_url":"https://github.com/grpc/grpc-go/pull/600","diff_url":"https://github.com/grpc/grpc-go/pull/600.diff","patch_url":"https://github.com/grpc/grpc-go/pull/600.patch","issue_url":"https://api.github.com/repos/grpc/grpc-go/issues/600","number":600,"state":"open","locked":false,"title":"Allow serviceAccount to reuse auth tokens.","user":{"login":"jmuk","id":816093,"avatar_url":"https://avatars.githubusercontent.com/u/816093?v=3","gravatar_id":"","url":"https://api.github.com/users/jmuk","html_url":"https://github.com/jmuk","followers_url":"https://api.github.com/users/jmuk/followers","following_url":"https://api.github.com/users/jmuk/following{/other_user}","gists_url":"https://api.github.com/users/jmuk/gists{/gist_id}","starred_url":"https://api.github.com/users/jmuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmuk/subscriptions","organizations_url":"https://api.github.com/users/jmuk/orgs","repos_url":"https://api.github.com/users/jmuk/repos","events_url":"https://api.github.com/users/jmuk/events{/privacy}","received_events_url":"https://api.github.com/users/jmuk/received_events","type":"User","site_admin":false},"body":"jwt.Config.TokenSource() actually returns a reusable token source,\r\nbut serviceAccount actually discards the reusability, it always\r\ncreates a new token source instance.\r\n\r\nThis patch could introduces a redundancy when the token expires;\r\ns.tokenSource.Token() implicitly attempts to obtain the new token\r\nwith the old context (the context which s.tokenSource was created\r\nwith), and if it fails, a new token source will be created with\r\na new context and then it attempts to obtain the token again.\r\n\r\nI believe this redundancy is ignorable mostly, because this method\r\nfalls into one of the following scenarios:\r\n- the same context is used among a program or the current sequence\r\n  of gRPC calls. Then the 'old context' and the 'new context' are\r\n  actually same.\r\n- the old context has enough time by the deadline; simply\r\n  obtaining the new token with the old context succeeds. The new\r\n  context is not used at all.\r\n- the old context is already canceled (or deadline exceeded). Then\r\n  the attempt with the old context fails immediately and switches\r\n  to create a new context.\r\n\r\nOn the other hand, cancelling the old context or some deadline\r\nsettings could lead to the inefficient code path theoretically.\r\nI think that is quite rare though.","created_at":"2016-03-22T23:29:12Z","updated_at":"2016-04-11T03:41:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4c927c2d6c7072f073e9f7dafb34aaba779d33f8","assignee":{"login":"adg","id":8446613,"avatar_url":"https://avatars.githubusercontent.com/u/8446613?v=3","gravatar_id":"","url":"https://api.github.com/users/adg","html_url":"https://github.com/adg","followers_url":"https://api.github.com/users/adg/followers","following_url":"https://api.github.com/users/adg/following{/other_user}","gists_url":"https://api.github.com/users/adg/gists{/gist_id}","starred_url":"https://api.github.com/users/adg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adg/subscriptions","organizations_url":"https://api.github.com/users/adg/orgs","repos_url":"https://api.github.com/users/adg/repos","events_url":"https://api.github.com/users/adg/events{/privacy}","received_events_url":"https://api.github.com/users/adg/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/grpc/grpc-go/pulls/600/commits","review_comments_url":"https://api.github.com/repos/grpc/grpc-go/pulls/600/comments","review_comment_url":"https://api.github.com/repos/grpc/grpc-go/pulls/comments{/number}","comments_url":"https://api.github.com/repos/grpc/grpc-go/issues/600/comments","statuses_url":"https://api.github.com/repos/grpc/grpc-go/statuses/94e39d128c9bf0fb42ecb1ea411fdacd1ee33b32","head":{"label":"jmuk:reuse_tokenstore_serviceaccount","ref":"reuse_tokenstore_serviceaccount","sha":"94e39d128c9bf0fb42ecb1ea411fdacd1ee33b32","user":{"login":"jmuk","id":816093,"avatar_url":"https://avatars.githubusercontent.com/u/816093?v=3","gravatar_id":"","url":"https://api.github.com/users/jmuk","html_url":"https://github.com/jmuk","followers_url":"https://api.github.com/users/jmuk/followers","following_url":"https://api.github.com/users/jmuk/following{/other_user}","gists_url":"https://api.github.com/users/jmuk/gists{/gist_id}","starred_url":"https://api.github.com/users/jmuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmuk/subscriptions","organizations_url":"https://api.github.com/users/jmuk/orgs","repos_url":"https://api.github.com/users/jmuk/repos","events_url":"https://api.github.com/users/jmuk/events{/privacy}","received_events_url":"https://api.github.com/users/jmuk/received_events","type":"User","site_admin":false},"repo":{"id":53893455,"name":"grpc-go","full_name":"jmuk/grpc-go","owner":{"login":"jmuk","id":816093,"avatar_url":"https://avatars.githubusercontent.com/u/816093?v=3","gravatar_id":"","url":"https://api.github.com/users/jmuk","html_url":"https://github.com/jmuk","followers_url":"https://api.github.com/users/jmuk/followers","following_url":"https://api.github.com/users/jmuk/following{/other_user}","gists_url":"https://api.github.com/users/jmuk/gists{/gist_id}","starred_url":"https://api.github.com/users/jmuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmuk/subscriptions","organizations_url":"https://api.github.com/users/jmuk/orgs","repos_url":"https://api.github.com/users/jmuk/repos","events_url":"https://api.github.com/users/jmuk/events{/privacy}","received_events_url":"https://api.github.com/users/jmuk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jmuk/grpc-go","description":"The Go language implementation of gRPC. HTTP/2 based RPC","fork":true,"url":"https://api.github.com/repos/jmuk/grpc-go","forks_url":"https://api.github.com/repos/jmuk/grpc-go/forks","keys_url":"https://api.github.com/repos/jmuk/grpc-go/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jmuk/grpc-go/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jmuk/grpc-go/teams","hooks_url":"https://api.github.com/repos/jmuk/grpc-go/hooks","issue_events_url":"https://api.github.com/repos/jmuk/grpc-go/issues/events{/number}","events_url":"https://api.github.com/repos/jmuk/grpc-go/events","assignees_url":"https://api.github.com/repos/jmuk/grpc-go/assignees{/user}","branches_url":"https://api.github.com/repos/jmuk/grpc-go/branches{/branch}","tags_url":"https://api.github.com/repos/jmuk/grpc-go/tags","blobs_url":"https://api.github.com/repos/jmuk/grpc-go/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jmuk/grpc-go/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jmuk/grpc-go/git/refs{/sha}","trees_url":"https://api.github.com/repos/jmuk/grpc-go/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jmuk/grpc-go/statuses/{sha}","languages_url":"https://api.github.com/repos/jmuk/grpc-go/languages","stargazers_url":"https://api.github.com/repos/jmuk/grpc-go/stargazers","contributors_url":"https://api.github.com/repos/jmuk/grpc-go/contributors","subscribers_url":"https://api.github.com/repos/jmuk/grpc-go/subscribers","subscription_url":"https://api.github.com/repos/jmuk/grpc-go/subscription","commits_url":"https://api.github.com/repos/jmuk/grpc-go/commits{/sha}","git_commits_url":"https://api.github.com/repos/jmuk/grpc-go/git/commits{/sha}","comments_url":"https://api.github.com/repos/jmuk/grpc-go/comments{/number}","issue_comment_url":"https://api.github.com/repos/jmuk/grpc-go/issues/comments{/number}","contents_url":"https://api.github.com/repos/jmuk/grpc-go/contents/{+path}","compare_url":"https://api.github.com/repos/jmuk/grpc-go/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jmuk/grpc-go/merges","archive_url":"https://api.github.com/repos/jmuk/grpc-go/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jmuk/grpc-go/downloads","issues_url":"https://api.github.com/repos/jmuk/grpc-go/issues{/number}","pulls_url":"https://api.github.com/repos/jmuk/grpc-go/pulls{/number}","milestones_url":"https://api.github.com/repos/jmuk/grpc-go/milestones{/number}","notifications_url":"https://api.github.com/repos/jmuk/grpc-go/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jmuk/grpc-go/labels{/name}","releases_url":"https://api.github.com/repos/jmuk/grpc-go/releases{/id}","deployments_url":"https://api.github.com/repos/jmuk/grpc-go/deployments","created_at":"2016-03-14T21:33:18Z","updated_at":"2016-03-14T21:33:19Z","pushed_at":"2016-03-22T23:28:52Z","git_url":"git://github.com/jmuk/grpc-go.git","ssh_url":"git@github.com:jmuk/grpc-go.git","clone_url":"https://github.com/jmuk/grpc-go.git","svn_url":"https://github.com/jmuk/grpc-go","homepage":"","size":1534,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"grpc:master","ref":"master","sha":"9e3a674ceba65708273cf1cd8e71a1bdce68107b","user":{"login":"grpc","id":7802525,"avatar_url":"https://avatars.githubusercontent.com/u/7802525?v=3","gravatar_id":"","url":"https://api.github.com/users/grpc","html_url":"https://github.com/grpc","followers_url":"https://api.github.com/users/grpc/followers","following_url":"https://api.github.com/users/grpc/following{/other_user}","gists_url":"https://api.github.com/users/grpc/gists{/gist_id}","starred_url":"https://api.github.com/users/grpc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grpc/subscriptions","organizations_url":"https://api.github.com/users/grpc/orgs","repos_url":"https://api.github.com/users/grpc/repos","events_url":"https://api.github.com/users/grpc/events{/privacy}","received_events_url":"https://api.github.com/users/grpc/received_events","type":"Organization","site_admin":false},"repo":{"id":27729907,"name":"grpc-go","full_name":"grpc/grpc-go","owner":{"login":"grpc","id":7802525,"avatar_url":"https://avatars.githubusercontent.com/u/7802525?v=3","gravatar_id":"","url":"https://api.github.com/users/grpc","html_url":"https://github.com/grpc","followers_url":"https://api.github.com/users/grpc/followers","following_url":"https://api.github.com/users/grpc/following{/other_user}","gists_url":"https://api.github.com/users/grpc/gists{/gist_id}","starred_url":"https://api.github.com/users/grpc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grpc/subscriptions","organizations_url":"https://api.github.com/users/grpc/orgs","repos_url":"https://api.github.com/users/grpc/repos","events_url":"https://api.github.com/users/grpc/events{/privacy}","received_events_url":"https://api.github.com/users/grpc/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/grpc/grpc-go","description":"The Go language implementation of gRPC. HTTP/2 based RPC","fork":false,"url":"https://api.github.com/repos/grpc/grpc-go","forks_url":"https://api.github.com/repos/grpc/grpc-go/forks","keys_url":"https://api.github.com/repos/grpc/grpc-go/keys{/key_id}","collaborators_url":"https://api.github.com/repos/grpc/grpc-go/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/grpc/grpc-go/teams","hooks_url":"https://api.github.com/repos/grpc/grpc-go/hooks","issue_events_url":"https://api.github.com/repos/grpc/grpc-go/issues/events{/number}","events_url":"https://api.github.com/repos/grpc/grpc-go/events","assignees_url":"https://api.github.com/repos/grpc/grpc-go/assignees{/user}","branches_url":"https://api.github.com/repos/grpc/grpc-go/branches{/branch}","tags_url":"https://api.github.com/repos/grpc/grpc-go/tags","blobs_url":"https://api.github.com/repos/grpc/grpc-go/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/grpc/grpc-go/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/grpc/grpc-go/git/refs{/sha}","trees_url":"https://api.github.com/repos/grpc/grpc-go/git/trees{/sha}","statuses_url":"https://api.github.com/repos/grpc/grpc-go/statuses/{sha}","languages_url":"https://api.github.com/repos/grpc/grpc-go/languages","stargazers_url":"https://api.github.com/repos/grpc/grpc-go/stargazers","contributors_url":"https://api.github.com/repos/grpc/grpc-go/contributors","subscribers_url":"https://api.github.com/repos/grpc/grpc-go/subscribers","subscription_url":"https://api.github.com/repos/grpc/grpc-go/subscription","commits_url":"https://api.github.com/repos/grpc/grpc-go/commits{/sha}","git_commits_url":"https://api.github.com/repos/grpc/grpc-go/git/commits{/sha}","comments_url":"https://api.github.com/repos/grpc/grpc-go/comments{/number}","issue_comment_url":"https://api.github.com/repos/grpc/grpc-go/issues/comments{/number}","contents_url":"https://api.github.com/repos/grpc/grpc-go/contents/{+path}","compare_url":"https://api.github.com/repos/grpc/grpc-go/compare/{base}...{head}","merges_url":"https://api.github.com/repos/grpc/grpc-go/merges","archive_url":"https://api.github.com/repos/grpc/grpc-go/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/grpc/grpc-go/downloads","issues_url":"https://api.github.com/repos/grpc/grpc-go/issues{/number}","pulls_url":"https://api.github.com/repos/grpc/grpc-go/pulls{/number}","milestones_url":"https://api.github.com/repos/grpc/grpc-go/milestones{/number}","notifications_url":"https://api.github.com/repos/grpc/grpc-go/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/grpc/grpc-go/labels{/name}","releases_url":"https://api.github.com/repos/grpc/grpc-go/releases{/id}","deployments_url":"https://api.github.com/repos/grpc/grpc-go/deployments","created_at":"2014-12-08T18:59:34Z","updated_at":"2016-04-11T03:10:02Z","pushed_at":"2016-04-08T19:17:51Z","git_url":"git://github.com/grpc/grpc-go.git","ssh_url":"git@github.com:grpc/grpc-go.git","clone_url":"https://github.com/grpc/grpc-go.git","svn_url":"https://github.com/grpc/grpc-go","homepage":"","size":2185,"stargazers_count":1635,"watchers_count":1635,"language":"Go","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":229,"mirror_url":null,"open_issues_count":63,"forks":229,"open_issues":63,"watchers":1635,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/grpc/grpc-go/pulls/600"},"html":{"href":"https://github.com/grpc/grpc-go/pull/600"},"issue":{"href":"https://api.github.com/repos/grpc/grpc-go/issues/600"},"comments":{"href":"https://api.github.com/repos/grpc/grpc-go/issues/600/comments"},"review_comments":{"href":"https://api.github.com/repos/grpc/grpc-go/pulls/600/comments"},"review_comment":{"href":"https://api.github.com/repos/grpc/grpc-go/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/grpc/grpc-go/pulls/600/commits"},"statuses":{"href":"https://api.github.com/repos/grpc/grpc-go/statuses/94e39d128c9bf0fb42ecb1ea411fdacd1ee33b32"}}}}