From 5fd42413edb3b1699004a31b72e485e0e4ba1b13 Mon Sep 17 00:00:00 2001 From: Carl Lundin Date: Fri, 10 May 2024 13:56:44 -0700 Subject: 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 https://github.com/googleapis/google-cloud-go/pull/9139 for the other auth library. Change-Id: Ifa353248197d8998e6b0363d1f2821b45a0e6495 Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/584815 Auto-Submit: Cody Oss TryBot-Bypass: Cody Oss Run-TryBot: Cody Oss TryBot-Result: Gopher Robot Reviewed-by: Cody Oss --- google/google.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/google/google.go b/google/google.go index ba931c2..7b82e7a 100644 --- a/google/google.go +++ b/google/google.go @@ -252,7 +252,10 @@ func (f *credentialsFile) tokenSource(ctx context.Context, params CredentialsPar // Further information about retrieving access tokens from the GCE metadata // server can be found at https://cloud.google.com/compute/docs/authentication. func ComputeTokenSource(account string, scope ...string) oauth2.TokenSource { - return computeTokenSource(account, 0, scope...) + // refresh 3 minutes and 45 seconds early. The shortest MDS cache is currently 4 minutes, so any + // refreshes earlier are a waste of compute. + earlyExpirySecs := 225 * time.Second + return computeTokenSource(account, earlyExpirySecs, scope...) } func computeTokenSource(account string, earlyExpiry time.Duration, scope ...string) oauth2.TokenSource { -- cgit v1.2.3