Add missing read unlock calls in transit backend code (#12652)

* Add missing read unlock calls in transit backend code

* Correct formatting in changelog entry
This commit is contained in:
divyapola5 2021-09-28 11:59:30 -05:00 committed by GitHub
parent 92046f7d08
commit 2a194a0804
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 7 deletions

View File

@ -122,11 +122,13 @@ func (b *backend) GetPolicy(ctx context.Context, polReq keysutil.PolicyRequest,
currentCacheSize := b.lm.GetCacheSize() currentCacheSize := b.lm.GetCacheSize()
storedCacheSize, err := GetCacheSizeFromStorage(ctx, polReq.Storage) storedCacheSize, err := GetCacheSizeFromStorage(ctx, polReq.Storage)
if err != nil { if err != nil {
b.configMutex.RUnlock()
return nil, false, err return nil, false, err
} }
if currentCacheSize != storedCacheSize { if currentCacheSize != storedCacheSize {
err = b.lm.InitCache(storedCacheSize) err = b.lm.InitCache(storedCacheSize)
if err != nil { if err != nil {
b.configMutex.RUnlock()
return nil, false, err return nil, false, err
} }
} }
@ -135,6 +137,8 @@ func (b *backend) GetPolicy(ctx context.Context, polReq keysutil.PolicyRequest,
b.configMutex.Lock() b.configMutex.Lock()
defer b.configMutex.Unlock() defer b.configMutex.Unlock()
b.cacheSizeChanged = false b.cacheSizeChanged = false
} else {
b.configMutex.RUnlock()
} }
p, _, err := b.lm.GetPolicy(ctx, polReq, rand) p, _, err := b.lm.GetPolicy(ctx, polReq, rand)
if err != nil { if err != nil {

View File

@ -86,16 +86,19 @@ func (b *backend) pathCacheConfigRead(ctx context.Context, req *logical.Request,
return nil, err return nil, err
} }
if currentCacheSize != storedCacheSize {
err = b.lm.InitCache(storedCacheSize)
if err != nil {
return nil, err
}
}
resp := &logical.Response{ resp := &logical.Response{
Data: map[string]interface{}{ Data: map[string]interface{}{
"size": storedCacheSize, "size": storedCacheSize,
}, },
} }
if currentCacheSize != storedCacheSize {
resp.Warnings = []string{"This cache size will not be applied until the transit mount is reloaded"}
}
return resp, nil return resp, nil
} }

View File

@ -1,4 +1,3 @@
```release-note:bug ```release-note:bug
Enforce minimum cache size for transit backend. secrets/transit: Enforce minimum cache size for transit backend and init cache size on transit backend without restart.
Init cache size on transit backend without restart. ```
```