Skip to content

Commit c387ab8

Browse files
committed
Store a pointer to a bearerToken in tokenCache
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č <[email protected]>
1 parent 2df9956 commit c387ab8

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

image/docker/docker_client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ type dockerClient struct {
118118

119119
// Private state for setupRequestAuth
120120
tokenCacheLock sync.Mutex // Protects tokenCache.
121-
tokenCache map[string]bearerToken
121+
tokenCache map[string]*bearerToken
122122
// Private state for detectProperties:
123123
detectPropertiesOnce sync.Once // detectPropertiesOnce is used to execute detectProperties() at most once.
124124
detectPropertiesError error // detectPropertiesError caches the initial error.
@@ -275,7 +275,7 @@ func newDockerClient(sys *types.SystemContext, registry, reference string) (*doc
275275
registry: registry,
276276
userAgent: userAgent,
277277
tlsClientConfig: tlsClientConfig,
278-
tokenCache: map[string]bearerToken{},
278+
tokenCache: map[string]*bearerToken{},
279279
reportedWarnings: set.New[string](),
280280
}, nil
281281
}
@@ -756,7 +756,7 @@ func (c *dockerClient) obtainBearerToken(ctx context.Context, challenge challeng
756756
scopes = append(scopes, *extraScope)
757757
}
758758

759-
var token bearerToken
759+
var token *bearerToken
760760
var inCache bool
761761
func() { // A scope for defer
762762
c.tokenCacheLock.Lock()
@@ -777,7 +777,7 @@ func (c *dockerClient) obtainBearerToken(ctx context.Context, challenge challeng
777777
return "", err
778778
}
779779

780-
token = *t
780+
token = t
781781
func() { // A scope for defer
782782
c.tokenCacheLock.Lock()
783783
defer c.tokenCacheLock.Unlock()

0 commit comments

Comments
 (0)