Fix data races.
This commit is contained in:
parent
9790aa91fe
commit
bcadd68904
2 changed files with 7 additions and 4 deletions
|
@ -19,9 +19,9 @@ type Handler struct {
|
||||||
Dashboard bool `description:"Activate dashboard" export:"true"`
|
Dashboard bool `description:"Activate dashboard" export:"true"`
|
||||||
Debug bool `export:"true"`
|
Debug bool `export:"true"`
|
||||||
CurrentConfigurations *safe.Safe
|
CurrentConfigurations *safe.Safe
|
||||||
Statistics *types.Statistics `description:"Enable more detailed statistics" export:"true"`
|
Statistics *types.Statistics `description:"Enable more detailed statistics" export:"true"`
|
||||||
Stats *thoas_stats.Stats
|
Stats *thoas_stats.Stats `json:"-"`
|
||||||
StatsRecorder *middlewares.StatsRecorder
|
StatsRecorder *middlewares.StatsRecorder `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -48,6 +48,7 @@ type BackendHealthCheck struct {
|
||||||
|
|
||||||
//HealthCheck struct
|
//HealthCheck struct
|
||||||
type HealthCheck struct {
|
type HealthCheck struct {
|
||||||
|
mutex sync.Mutex
|
||||||
Backends map[string]*BackendHealthCheck
|
Backends map[string]*BackendHealthCheck
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
}
|
}
|
||||||
|
@ -75,14 +76,16 @@ func NewBackendHealthCheck(options Options) *BackendHealthCheck {
|
||||||
|
|
||||||
//SetBackendsConfiguration set backends configuration
|
//SetBackendsConfiguration set backends configuration
|
||||||
func (hc *HealthCheck) SetBackendsConfiguration(parentCtx context.Context, backends map[string]*BackendHealthCheck) {
|
func (hc *HealthCheck) SetBackendsConfiguration(parentCtx context.Context, backends map[string]*BackendHealthCheck) {
|
||||||
|
hc.mutex.Lock()
|
||||||
hc.Backends = backends
|
hc.Backends = backends
|
||||||
if hc.cancel != nil {
|
if hc.cancel != nil {
|
||||||
hc.cancel()
|
hc.cancel()
|
||||||
}
|
}
|
||||||
ctx, cancel := context.WithCancel(parentCtx)
|
ctx, cancel := context.WithCancel(parentCtx)
|
||||||
hc.cancel = cancel
|
hc.cancel = cancel
|
||||||
|
hc.mutex.Unlock()
|
||||||
|
|
||||||
for backendID, backend := range hc.Backends {
|
for backendID, backend := range backends {
|
||||||
currentBackendID := backendID
|
currentBackendID := backendID
|
||||||
currentBackend := backend
|
currentBackend := backend
|
||||||
safe.Go(func() {
|
safe.Go(func() {
|
||||||
|
|
Loading…
Reference in a new issue