Skip to content

Commit f91a586

Browse files
committed
fix: inline proxy provider's healthcheck not work
1 parent 266fb03 commit f91a586

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

adapter/provider/healthcheck.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (hc *HealthCheck) process() {
6161
}
6262
}
6363

64-
func (hc *HealthCheck) setProxy(proxies []C.Proxy) {
64+
func (hc *HealthCheck) setProxies(proxies []C.Proxy) {
6565
hc.proxies = proxies
6666
}
6767

adapter/provider/provider.go

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ func (bp *baseProvider) Version() uint32 {
5757
return bp.version
5858
}
5959

60+
func (bp *baseProvider) Initial() error {
61+
if bp.healthCheck.auto() {
62+
go bp.healthCheck.process()
63+
}
64+
return nil
65+
}
66+
6067
func (bp *baseProvider) HealthCheck() {
6168
bp.healthCheck.check()
6269
}
@@ -88,7 +95,7 @@ func (bp *baseProvider) RegisterHealthCheckTask(url string, expectedStatus utils
8895
func (bp *baseProvider) setProxies(proxies []C.Proxy) {
8996
bp.proxies = proxies
9097
bp.version += 1
91-
bp.healthCheck.setProxy(proxies)
98+
bp.healthCheck.setProxies(proxies)
9299
if bp.healthCheck.auto() {
93100
go bp.healthCheck.check()
94101
}
@@ -133,8 +140,8 @@ func (pp *proxySetProvider) Update() error {
133140
}
134141

135142
func (pp *proxySetProvider) Initial() error {
136-
if pp.healthCheck.auto() {
137-
go pp.healthCheck.process()
143+
if err := pp.baseProvider.Initial(); err != nil {
144+
return err
138145
}
139146
_, err := pp.Fetcher.Initial()
140147
if err != nil {
@@ -184,6 +191,8 @@ func NewProxySetProvider(name string, interval time.Duration, payload []map[stri
184191
return nil, err
185192
}
186193
pd.proxies = proxies
194+
// direct call setProxies on hc to avoid starting a health check process immediately, it should be done by Initial()
195+
hc.setProxies(proxies)
187196
}
188197

189198
fetcher := resource.NewFetcher[[]C.Proxy](name, interval, vehicle, parser, pd.setProxies)
@@ -233,13 +242,6 @@ func (ip *inlineProvider) VehicleType() types.VehicleType {
233242
return types.Inline
234243
}
235244

236-
func (ip *inlineProvider) Initial() error {
237-
if ip.healthCheck.auto() {
238-
go ip.healthCheck.process()
239-
}
240-
return nil
241-
}
242-
243245
func (ip *inlineProvider) Update() error {
244246
// make api update happy
245247
ip.updateAt = time.Now()
@@ -256,6 +258,8 @@ func NewInlineProvider(name string, payload []map[string]any, parser resource.Pa
256258
if err != nil {
257259
return nil, err
258260
}
261+
// direct call setProxies on hc to avoid starting a health check process immediately, it should be done by Initial()
262+
hc.setProxies(proxies)
259263

260264
ip := &inlineProvider{
261265
baseProvider: baseProvider{
@@ -299,13 +303,6 @@ func (cp *compatibleProvider) Update() error {
299303
return nil
300304
}
301305

302-
func (cp *compatibleProvider) Initial() error {
303-
if cp.healthCheck.auto() {
304-
go cp.healthCheck.process()
305-
}
306-
return nil
307-
}
308-
309306
func (cp *compatibleProvider) VehicleType() types.VehicleType {
310307
return types.Compatible
311308
}

0 commit comments

Comments
 (0)