From 76e9607fd71e17a1886bbf699350c863bfa68e29 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Tue, 13 May 2025 01:10:10 +0800 Subject: [PATCH] chore: move start healthcheck.process() from New to Initial in provider avoid panic cause by build-in proxy have not set to tunnel --- adapter/provider/healthcheck.go | 11 ----------- adapter/provider/provider.go | 21 +++++++++------------ 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/adapter/provider/healthcheck.go b/adapter/provider/healthcheck.go index dafdbb115..f16718e92 100644 --- a/adapter/provider/healthcheck.go +++ b/adapter/provider/healthcheck.go @@ -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) { diff --git a/adapter/provider/provider.go b/adapter/provider/provider.go index 7bd80d32f..8c88d1e8b 100644 --- a/adapter/provider/provider.go +++ b/adapter/provider/provider.go @@ -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,