From e7155e1d4515f268decd9473dd82dc47c5b00a06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Mon, 29 May 2023 22:29:17 +0200 Subject: [PATCH] Store a pointer to a bearerToken in tokenCache MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We will want to add a lock to it, so we must stop copying it by value. Should not change behavior. Signed-off-by: Miloslav Trmač --- docker/docker_client.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docker/docker_client.go b/docker/docker_client.go index 718e810bf..4da5c0139 100644 --- a/docker/docker_client.go +++ b/docker/docker_client.go @@ -118,7 +118,7 @@ type dockerClient struct { // Private state for setupRequestAuth (key: string, value: bearerToken) tokenCacheLock sync.Mutex // Protects tokenCache - tokenCache map[string]bearerToken + tokenCache map[string]*bearerToken // Private state for detectProperties: detectPropertiesOnce sync.Once // detectPropertiesOnce is used to execute detectProperties() at most once. detectPropertiesError error // detectPropertiesError caches the initial error. @@ -270,7 +270,7 @@ func newDockerClient(sys *types.SystemContext, registry, reference string) (*doc registry: registry, userAgent: userAgent, tlsClientConfig: tlsClientConfig, - tokenCache: map[string]bearerToken{}, + tokenCache: map[string]*bearerToken{}, reportedWarnings: set.New[string](), }, nil } @@ -752,7 +752,7 @@ func (c *dockerClient) obtainBearerToken(ctx context.Context, challenge challeng scopes = append(scopes, *extraScope) } - var token bearerToken + var token *bearerToken var inCache bool func() { // A scope for defer c.tokenCacheLock.Lock() @@ -773,7 +773,7 @@ func (c *dockerClient) obtainBearerToken(ctx context.Context, challenge challeng return "", err } - token = *t + token = t func() { // A scope for defer c.tokenCacheLock.Lock() defer c.tokenCacheLock.Unlock()