From 0d33dc3eb9bce2d89e54406e8dea275adb99e4b0 Mon Sep 17 00:00:00 2001 From: Kr328 Date: Tue, 24 Nov 2020 22:52:23 +0800 Subject: [PATCH] Chore: health checks return immediately if completed (#1097) --- adapters/provider/healthcheck.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/adapters/provider/healthcheck.go b/adapters/provider/healthcheck.go index d741ed7f3..98f934e42 100644 --- a/adapters/provider/healthcheck.go +++ b/adapters/provider/healthcheck.go @@ -2,6 +2,7 @@ package provider import ( "context" + "sync" "time" C "github.com/Dreamacro/clash/constant" @@ -59,11 +60,18 @@ func (hc *HealthCheck) touch() { func (hc *HealthCheck) check() { ctx, cancel := context.WithTimeout(context.Background(), defaultURLTestTimeout) + wg := &sync.WaitGroup{} + for _, proxy := range hc.proxies { - go proxy.URLTest(ctx, hc.url) + wg.Add(1) + + go func(p C.Proxy) { + p.URLTest(ctx, hc.url) + wg.Done() + }(proxy) } - <-ctx.Done() + wg.Wait() cancel() }