chore: move start healthcheck.process() from New to Initial in provider

avoid panic cause by build-in proxy have not set to tunnel
This commit is contained in:
wwqgtxx 2025-05-13 01:10:10 +08:00
parent 23e2d3a132
commit 76e9607fd7
2 changed files with 9 additions and 23 deletions

View File

@ -32,7 +32,6 @@ type HealthCheck struct {
url string
extra map[string]*extraOption
mu sync.Mutex
started atomic.Bool
proxies []C.Proxy
interval time.Duration
lazy bool
@ -43,12 +42,6 @@ type HealthCheck struct {
}
func (hc *HealthCheck) process() {
if !hc.started.CompareAndSwap(false, true) {
log.Warnln("Skip start health check timer due to it's started")
return
}
defer hc.started.Store(false)
ticker := time.NewTicker(hc.interval)
go hc.check()
for {
@ -105,10 +98,6 @@ func (hc *HealthCheck) registerHealthCheckTask(url string, expectedStatus utils.
option := &extraOption{filters: map[string]struct{}{}, expectedStatus: expectedStatus}
splitAndAddFiltersToExtra(filter, option)
hc.extra[url] = option
if hc.auto() && !hc.started.Load() {
go hc.process()
}
}
func splitAndAddFiltersToExtra(filter string, option *extraOption) {

View File

@ -133,6 +133,9 @@ func (pp *proxySetProvider) Update() error {
}
func (pp *proxySetProvider) Initial() error {
if pp.healthCheck.auto() {
go pp.healthCheck.process()
}
_, err := pp.Fetcher.Initial()
if err != nil {
return err
@ -162,10 +165,6 @@ func (pp *proxySetProvider) Close() error {
}
func NewProxySetProvider(name string, interval time.Duration, payload []map[string]any, parser resource.Parser[[]C.Proxy], vehicle types.Vehicle, hc *HealthCheck) (*ProxySetProvider, error) {
if hc.auto() {
go hc.process()
}
pd := &proxySetProvider{
baseProvider: baseProvider{
name: name,
@ -235,6 +234,9 @@ func (ip *inlineProvider) VehicleType() types.VehicleType {
}
func (ip *inlineProvider) Initial() error {
if ip.healthCheck.auto() {
go ip.healthCheck.process()
}
return nil
}
@ -245,10 +247,6 @@ func (ip *inlineProvider) Update() error {
}
func NewInlineProvider(name string, payload []map[string]any, parser resource.Parser[[]C.Proxy], hc *HealthCheck) (*InlineProvider, error) {
if hc.auto() {
go hc.process()
}
ps := ProxySchema{Proxies: payload}
buf, err := yaml.Marshal(ps)
if err != nil {
@ -302,6 +300,9 @@ func (cp *compatibleProvider) Update() error {
}
func (cp *compatibleProvider) Initial() error {
if cp.healthCheck.auto() {
go cp.healthCheck.process()
}
return nil
}
@ -314,10 +315,6 @@ func NewCompatibleProvider(name string, proxies []C.Proxy, hc *HealthCheck) (*Co
return nil, errors.New("provider need one proxy at least")
}
if hc.auto() {
go hc.process()
}
pd := &compatibleProvider{
baseProvider: baseProvider{
name: name,