Skip to content
Snippets Groups Projects
Commit e59c47b7 authored by Benjamin Wenger's avatar Benjamin Wenger
Browse files

fixes to the health tracker stopper

parent e53af121
No related branches found
No related tags found
No related merge requests found
......@@ -103,7 +103,6 @@ func (t *Tracker) setHealth(h bool) {
func (t *Tracker) Start() (stoppable.Stoppable, error) {
t.mux.Lock()
defer t.mux.Unlock()
if t.running {
return nil, errors.New("cannot start Health tracker threads, " +
"they are already running")
......@@ -111,20 +110,13 @@ func (t *Tracker) Start() (stoppable.Stoppable, error) {
t.running = true
t.isHealthy = false
t.mux.Unlock()
stop := stoppable.NewSingle("Health Tracker")
stopCleanup := stoppable.NewCleanup(stop, func(duration time.Duration) error {
t.mux.Lock()
defer t.mux.Unlock()
t.isHealthy = false
t.transmit(false)
t.running = false
return nil
})
go t.start(stop.Quit())
return stopCleanup, nil
return stop, nil
}
// Long-running thread used to monitor and report on network health
......@@ -135,7 +127,11 @@ func (t *Tracker) start(quitCh <-chan struct{}) {
var heartbeat network.Heartbeat
select {
case <-quitCh:
// Handle thread kill
t.mux.Lock()
t.isHealthy = false
t.running = false
t.mux.Unlock()
t.transmit(false)
break
case heartbeat = <-t.heartbeat:
if healthy(heartbeat) {
......
......@@ -9,11 +9,11 @@ package stoppable
import (
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/xx_network/primitives/netTime"
"sync"
"sync/atomic"
"time"
jww "github.com/spf13/jwalterweatherman"
)
// Cleanup wraps any stoppable and runs a callback after to stop for cleanup
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment