Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address a data race setting seal wrapper health attributes #27014

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading