Skip to content

Commit 0da5d21

Browse files
committed
fix concurrency issue in venafi cloud client
Spotted by @George-Yanev Signed-off-by: Ashley Davis <ashley.davis@cyberark.com>
1 parent 4445a6b commit 0da5d21

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

pkg/client/client_venafi_cloud.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,22 @@ func (c *VenafiCloudClient) post(ctx context.Context, path string, body io.Reade
259259
// token from the auth server in case the current access token does not exist
260260
// or it is expired.
261261
func (c *VenafiCloudClient) getValidAccessToken(ctx context.Context) (*venafiCloudAccessToken, error) {
262-
if c.accessToken == nil || time.Now().Add(time.Minute).After(c.accessToken.expirationTime) {
262+
c.lock.RLock()
263+
needsUpdate := c.accessToken == nil || time.Now().Add(time.Minute).After(c.accessToken.expirationTime)
264+
c.lock.RUnlock()
265+
266+
if needsUpdate {
263267
err := c.updateAccessToken(ctx)
264268
if err != nil {
265269
return nil, err
266270
}
267271
}
268272

269-
return c.accessToken, nil
273+
c.lock.RLock()
274+
token := c.accessToken
275+
c.lock.RUnlock()
276+
277+
return token, nil
270278
}
271279

272280
func (c *VenafiCloudClient) updateAccessToken(ctx context.Context) error {

0 commit comments

Comments
 (0)