synchronize refreshing GCP access tokens
avoid unnecessary calls to refresh(), even if internally the method is
synchronized and threadsafe.
@@ -178,8 +178,8 @@ public class ContainerRegistryAuthSupplier implements RegistryAuthSupplier {
* minimumExpiryMillis.
*/
private AccessToken getAccessToken() throws DockerException {
- // there is a small chance of multiple threads calling refresh() many times, but the
- // GoogleCredentials implementation has thread-safe behavior internally
+ // synchronize attempts to refresh the accessToken
+ synchronized (credentials) {
if (needsRefresh(credentials.getAccessToken())) {
try {
credentialRefresher.refresh(credentials);
@@ -188,7 +188,7 @@ public class ContainerRegistryAuthSupplier implements RegistryAuthSupplier {
throw new DockerException("Could not refresh access token", e);
}
}
-
+ }
return credentials.getAccessToken();
}
