Skip to content

Commit

Permalink
Add missing read unlock calls in transit backend code (#12652) (#12662)
Browse files Browse the repository at this point in the history
* Add missing read unlock calls in transit backend code

* Correct formatting in changelog entry
  • Loading branch information
divyapola5 committed Sep 28, 2021
1 parent c3a48b1 commit 73e85c3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 4 additions & 0 deletions builtin/logical/transit/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,13 @@ func (b *backend) GetPolicy(ctx context.Context, polReq keysutil.PolicyRequest,
currentCacheSize := b.lm.GetCacheSize()
storedCacheSize, err := GetCacheSizeFromStorage(ctx, polReq.Storage)
if err != nil {
b.configMutex.RUnlock()
return nil, false, err
}
if currentCacheSize != storedCacheSize {
err = b.lm.InitCache(storedCacheSize)
if err != nil {
b.configMutex.RUnlock()
return nil, false, err
}
}
Expand All @@ -135,6 +137,8 @@ func (b *backend) GetPolicy(ctx context.Context, polReq keysutil.PolicyRequest,
b.configMutex.Lock()
defer b.configMutex.Unlock()
b.cacheSizeChanged = false
} else {
b.configMutex.RUnlock()
}
p, _, err := b.lm.GetPolicy(ctx, polReq, rand)
if err != nil {
Expand Down
11 changes: 7 additions & 4 deletions builtin/logical/transit/path_cache_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,19 @@ func (b *backend) pathCacheConfigRead(ctx context.Context, req *logical.Request,
return nil, err
}

if currentCacheSize != storedCacheSize {
err = b.lm.InitCache(storedCacheSize)
if err != nil {
return nil, err
}
}

resp := &logical.Response{
Data: map[string]interface{}{
"size": storedCacheSize,
},
}

if currentCacheSize != storedCacheSize {
resp.Warnings = []string{"This cache size will not be applied until the transit mount is reloaded"}
}

return resp, nil
}

Expand Down
5 changes: 2 additions & 3 deletions changelog/12418.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
```release-note:bug
Enforce minimum cache size for transit backend.
Init cache size on transit backend without restart.
```
secrets/transit: Enforce minimum cache size for transit backend and init cache size on transit backend without restart.
```

0 comments on commit 73e85c3

Please sign in to comment.