Skip to content

Commit

Permalink
backport of commit 029d151
Browse files Browse the repository at this point in the history
  • Loading branch information
stevendpclark authored May 14, 2024
1 parent 774468b commit 9215000
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
3 changes: 3 additions & 0 deletions changelog/27014.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
core: Address a data race updating a seal's last seen healthy time attribute
```
39 changes: 16 additions & 23 deletions vault/seal/seal_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
}

0 comments on commit 9215000

Please sign in to comment.