Skip to content

Commit 5fd4241

Browse files
clundin25gopherbot
authored andcommitted
google: update compute token refresh
The shortest MDS token cache time is 4 minutes. The refresh window is updated to 3 minutes and 45 seconds to give the MDS time to update it's cache. This should make slow refreshes less likely to cause failures. Done in googleapis/google-cloud-go#9139 for the other auth library. Change-Id: Ifa353248197d8998e6b0363d1f2821b45a0e6495 Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/584815 Auto-Submit: Cody Oss <[email protected]> TryBot-Bypass: Cody Oss <[email protected]> Run-TryBot: Cody Oss <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Cody Oss <[email protected]>
1 parent 84cb9f7 commit 5fd4241

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

google/google.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,10 @@ func (f *credentialsFile) tokenSource(ctx context.Context, params CredentialsPar
252252
// Further information about retrieving access tokens from the GCE metadata
253253
// server can be found at https://cloud.google.com/compute/docs/authentication.
254254
func ComputeTokenSource(account string, scope ...string) oauth2.TokenSource {
255-
return computeTokenSource(account, 0, scope...)
255+
// refresh 3 minutes and 45 seconds early. The shortest MDS cache is currently 4 minutes, so any
256+
// refreshes earlier are a waste of compute.
257+
earlyExpirySecs := 225 * time.Second
258+
return computeTokenSource(account, earlyExpirySecs, scope...)
256259
}
257260

258261
func computeTokenSource(account string, earlyExpiry time.Duration, scope ...string) oauth2.TokenSource {

0 commit comments

Comments
 (0)