Commit a8d98018 authored by Julius Volz's avatar Julius Volz

Fix data races around runner health and build stats

These were found by building with --race and running the runner for a
while.
parent cbf65211
......@@ -91,3 +91,10 @@ func (b *buildsHelper) removeBuild(deleteBuild *common.Build) bool {
}
return false
}
func (b *buildsHelper) buildsCount() int {
b.lock.Lock()
defer b.lock.Unlock()
return len(b.builds)
}
......@@ -19,9 +19,6 @@ type healthHelper struct {
}
func (mr *healthHelper) getHealth(id string) *healthData {
mr.healthyLock.Lock()
defer mr.healthyLock.Unlock()
if mr.healthy == nil {
mr.healthy = map[string]*healthData{}
}
......@@ -36,6 +33,9 @@ func (mr *healthHelper) getHealth(id string) *healthData {
}
func (mr *healthHelper) isHealthy(id string) bool {
mr.healthyLock.Lock()
defer mr.healthyLock.Unlock()
health := mr.getHealth(id)
if health.failures < common.HealthyChecks {
return true
......@@ -52,6 +52,9 @@ func (mr *healthHelper) isHealthy(id string) bool {
}
func (mr *healthHelper) makeHealthy(id string, healthy bool) {
mr.healthyLock.Lock()
defer mr.healthyLock.Unlock()
health := mr.getHealth(id)
if healthy {
health.failures = 0
......
......@@ -56,7 +56,7 @@ type RunCommand struct {
}
func (mr *RunCommand) log() *log.Entry {
return log.WithField("builds", len(mr.buildsHelper.builds))
return log.WithField("builds", mr.buildsHelper.buildsCount())
}
func (mr *RunCommand) feedRunner(runner *common.RunnerConfig, runners chan *common.RunnerConfig) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment