Skip to content

Commit

Permalink
Store a pointer to a bearerToken in tokenCache
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
mtrmac committed Jul 11, 2024
1 parent 10367f7 commit e7155e1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions docker/docker_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit e7155e1

Please sign in to comment.