Skip to content

Commit 76e9607

Browse files
committed
chore: move start healthcheck.process() from New to Initial in provider
avoid panic cause by build-in proxy have not set to tunnel
1 parent 23e2d3a commit 76e9607

File tree

2 files changed

+9
-23
lines changed

2 files changed

+9
-23
lines changed

adapter/provider/healthcheck.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ type HealthCheck struct {
3232
url string
3333
extra map[string]*extraOption
3434
mu sync.Mutex
35-
started atomic.Bool
3635
proxies []C.Proxy
3736
interval time.Duration
3837
lazy bool
@@ -43,12 +42,6 @@ type HealthCheck struct {
4342
}
4443

4544
func (hc *HealthCheck) process() {
46-
if !hc.started.CompareAndSwap(false, true) {
47-
log.Warnln("Skip start health check timer due to it's started")
48-
return
49-
}
50-
defer hc.started.Store(false)
51-
5245
ticker := time.NewTicker(hc.interval)
5346
go hc.check()
5447
for {
@@ -105,10 +98,6 @@ func (hc *HealthCheck) registerHealthCheckTask(url string, expectedStatus utils.
10598
option := &extraOption{filters: map[string]struct{}{}, expectedStatus: expectedStatus}
10699
splitAndAddFiltersToExtra(filter, option)
107100
hc.extra[url] = option
108-
109-
if hc.auto() && !hc.started.Load() {
110-
go hc.process()
111-
}
112101
}
113102

114103
func splitAndAddFiltersToExtra(filter string, option *extraOption) {

adapter/provider/provider.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ func (pp *proxySetProvider) Update() error {
133133
}
134134

135135
func (pp *proxySetProvider) Initial() error {
136+
if pp.healthCheck.auto() {
137+
go pp.healthCheck.process()
138+
}
136139
_, err := pp.Fetcher.Initial()
137140
if err != nil {
138141
return err
@@ -162,10 +165,6 @@ func (pp *proxySetProvider) Close() error {
162165
}
163166

164167
func NewProxySetProvider(name string, interval time.Duration, payload []map[string]any, parser resource.Parser[[]C.Proxy], vehicle types.Vehicle, hc *HealthCheck) (*ProxySetProvider, error) {
165-
if hc.auto() {
166-
go hc.process()
167-
}
168-
169168
pd := &proxySetProvider{
170169
baseProvider: baseProvider{
171170
name: name,
@@ -235,6 +234,9 @@ func (ip *inlineProvider) VehicleType() types.VehicleType {
235234
}
236235

237236
func (ip *inlineProvider) Initial() error {
237+
if ip.healthCheck.auto() {
238+
go ip.healthCheck.process()
239+
}
238240
return nil
239241
}
240242

@@ -245,10 +247,6 @@ func (ip *inlineProvider) Update() error {
245247
}
246248

247249
func NewInlineProvider(name string, payload []map[string]any, parser resource.Parser[[]C.Proxy], hc *HealthCheck) (*InlineProvider, error) {
248-
if hc.auto() {
249-
go hc.process()
250-
}
251-
252250
ps := ProxySchema{Proxies: payload}
253251
buf, err := yaml.Marshal(ps)
254252
if err != nil {
@@ -302,6 +300,9 @@ func (cp *compatibleProvider) Update() error {
302300
}
303301

304302
func (cp *compatibleProvider) Initial() error {
303+
if cp.healthCheck.auto() {
304+
go cp.healthCheck.process()
305+
}
305306
return nil
306307
}
307308

@@ -314,10 +315,6 @@ func NewCompatibleProvider(name string, proxies []C.Proxy, hc *HealthCheck) (*Co
314315
return nil, errors.New("provider need one proxy at least")
315316
}
316317

317-
if hc.auto() {
318-
go hc.process()
319-
}
320-
321318
pd := &compatibleProvider{
322319
baseProvider: baseProvider{
323320
name: name,

0 commit comments

Comments
 (0)