From e1fe9c61572f616b4035ee458d688a35bd6c0037 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Sun, 12 Dec 2021 20:37:30 +0800 Subject: [PATCH] Fix: when both providers and proxies are present, use the health check configuration for proxies (#1821) Co-authored-by: Ho --- adapter/outboundgroup/parser.go | 43 ++++++++++++--------------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/adapter/outboundgroup/parser.go b/adapter/outboundgroup/parser.go index 190d333d..fcf7e3b5 100644 --- a/adapter/outboundgroup/parser.go +++ b/adapter/outboundgroup/parser.go @@ -59,8 +59,12 @@ func ParseProxyGroup(config map[string]interface{}, proxyMap map[string]C.Proxy, return nil, err } - // if Use not empty, drop health check options - if len(groupOption.Use) != 0 { + if _, ok := providersMap[groupName]; ok { + return nil, errDuplicateProvider + } + + // select don't need health check + if groupOption.Type == "select" || groupOption.Type == "relay" { hc := provider.NewHealthCheck(ps, "", 0, true) pd, err := provider.NewCompatibleProvider(groupName, ps, hc) if err != nil { @@ -68,35 +72,20 @@ func ParseProxyGroup(config map[string]interface{}, proxyMap map[string]C.Proxy, } providers = append(providers, pd) + providersMap[groupName] = pd } else { - if _, ok := providersMap[groupName]; ok { - return nil, errDuplicateProvider + if groupOption.URL == "" || groupOption.Interval == 0 { + return nil, errMissHealthCheck } - // select don't need health check - if groupOption.Type == "select" || groupOption.Type == "relay" { - hc := provider.NewHealthCheck(ps, "", 0, true) - pd, err := provider.NewCompatibleProvider(groupName, ps, hc) - if err != nil { - return nil, err - } - - providers = append(providers, pd) - providersMap[groupName] = pd - } else { - if groupOption.URL == "" || groupOption.Interval == 0 { - return nil, errMissHealthCheck - } - - hc := provider.NewHealthCheck(ps, groupOption.URL, uint(groupOption.Interval), groupOption.Lazy) - pd, err := provider.NewCompatibleProvider(groupName, ps, hc) - if err != nil { - return nil, err - } - - providers = append(providers, pd) - providersMap[groupName] = pd + hc := provider.NewHealthCheck(ps, groupOption.URL, uint(groupOption.Interval), groupOption.Lazy) + pd, err := provider.NewCompatibleProvider(groupName, ps, hc) + if err != nil { + return nil, err } + + providers = append(providers, pd) + providersMap[groupName] = pd } }