Skip to content

Commit

Permalink
check client after grabbing lock
Browse files Browse the repository at this point in the history
  • Loading branch information
catsby committed Sep 18, 2018
1 parent cf9e95c commit 3d468da
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions builtin/logical/aws/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ func (b *backend) clientIAM(ctx context.Context, s logical.Storage) (iamiface.IA
// Upgrade the lock for writing
b.clientMutex.RUnlock()
b.clientMutex.Lock()
defer b.clientMutex.Unlock()

// check client again, in the event that a client was being created while we
// waited for Lock()
if b.iamClient != nil {
return b.iamClient, nil
}

iamClient, err := clientIAM(ctx, s)
if err != nil {
Expand All @@ -111,6 +118,13 @@ func (b *backend) clientSTS(ctx context.Context, s logical.Storage) (stsiface.ST
// Upgrade the lock for writing
b.clientMutex.RUnlock()
b.clientMutex.Lock()
defer b.clientMutex.Unlock()

// check client again, in the event that a client was being created while we
// waited for Lock()
if b.stsClient != nil {
return b.stsClient, nil
}

stsClient, err := clientSTS(ctx, s)
if err != nil {
Expand Down

0 comments on commit 3d468da

Please sign in to comment.