mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-06-13 21:54:13 +08:00
fix health check ticker interval and close
This commit is contained in:
parent
105a39d6e1
commit
fdfa66ea42
@ -27,6 +27,8 @@ type HealthCheck struct {
|
|||||||
|
|
||||||
options *option.HealthCheckSettings
|
options *option.HealthCheckSettings
|
||||||
results map[string]*result
|
results map[string]*result
|
||||||
|
|
||||||
|
close chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type result struct {
|
type result struct {
|
||||||
@ -73,15 +75,16 @@ func (h *HealthCheck) Start() error {
|
|||||||
if h.ticker != nil {
|
if h.ticker != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
interval := time.Duration(h.options.Interval) * time.Duration(h.options.SamplingCount)
|
h.close = make(chan struct{})
|
||||||
ticker := time.NewTicker(interval)
|
ticker := time.NewTicker(time.Duration(h.options.Interval))
|
||||||
h.ticker = ticker
|
h.ticker = ticker
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
|
select {
|
||||||
|
case <-h.close:
|
||||||
|
return
|
||||||
|
case <-ticker.C:
|
||||||
h.CheckNodes()
|
h.CheckNodes()
|
||||||
_, ok := <-ticker.C
|
|
||||||
if !ok {
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -96,6 +99,7 @@ func (h *HealthCheck) Close() error {
|
|||||||
h.ticker.Stop()
|
h.ticker.Stop()
|
||||||
h.ticker = nil
|
h.ticker = nil
|
||||||
}
|
}
|
||||||
|
close(h.close)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user