mirror of
https://github.com/hashicorp/vault.git
synced 2026-02-03 20:40:45 -05:00
Address a data race setting seal wrapper health attributes (#27014)
* Address a data race setting seal wrapper health attributes - When updating a seal wrapper's lastHealthCheck in a failure scenario we would read the lastSeenHealthy value in order to not update it outside of a locked context. This lead to the data race. - Merge the SetHealthy and setHealthy functions into one, in order to combine the logic and locking in a single function * Add cl
This commit is contained in:
parent
9e8d9db937
commit
029d151f0f
2 changed files with 19 additions and 23 deletions
3
changelog/27014.txt
Normal file
3
changelog/27014.txt
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
```release-note:bug
|
||||
core: Address a data race updating a seal's last seen healthy time attribute
|
||||
```
|
||||
|
|
@ -51,29 +51,32 @@ type SealWrapper struct {
|
|||
|
||||
func NewSealWrapper(wrapper wrapping.Wrapper, priority int, name string, sealConfigType string, disabled bool, configured bool) *SealWrapper {
|
||||
ret := &SealWrapper{
|
||||
Wrapper: wrapper,
|
||||
Priority: priority,
|
||||
Name: name,
|
||||
SealConfigType: sealConfigType,
|
||||
Disabled: disabled,
|
||||
Configured: configured,
|
||||
Wrapper: wrapper,
|
||||
Priority: priority,
|
||||
Name: name,
|
||||
SealConfigType: sealConfigType,
|
||||
Disabled: disabled,
|
||||
Configured: configured,
|
||||
lastSeenHealthy: time.Now(),
|
||||
healthy: false,
|
||||
}
|
||||
|
||||
if configured {
|
||||
setHealth(ret, true, time.Now(), ret.lastHealthCheck)
|
||||
} else {
|
||||
setHealth(ret, false, time.Now(), ret.lastHealthCheck)
|
||||
ret.healthy = true
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func (sw *SealWrapper) SetHealthy(healthy bool, checkTime time.Time) {
|
||||
sw.hcLock.Lock()
|
||||
defer sw.hcLock.Unlock()
|
||||
|
||||
sw.healthy = healthy
|
||||
sw.lastHealthCheck = checkTime
|
||||
|
||||
if healthy {
|
||||
setHealth(sw, true, checkTime, checkTime)
|
||||
} else {
|
||||
// do not update lastSeenHealthy
|
||||
setHealth(sw, false, sw.lastHealthCheck, checkTime)
|
||||
sw.lastSeenHealthy = checkTime
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -134,13 +137,3 @@ func getHealth(sw *SealWrapper) (healthy bool, lastSeenHealthy time.Time, lastHe
|
|||
|
||||
return sw.healthy, sw.lastSeenHealthy, sw.lastHealthCheck
|
||||
}
|
||||
|
||||
// setHealth is the only function allowed to mutate the health fields
|
||||
func setHealth(sw *SealWrapper, healthy bool, lastSeenHealthy, lastHealthCheck time.Time) {
|
||||
sw.hcLock.Lock()
|
||||
defer sw.hcLock.Unlock()
|
||||
|
||||
sw.healthy = healthy
|
||||
sw.lastSeenHealthy = lastSeenHealthy
|
||||
sw.lastHealthCheck = lastHealthCheck
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue