diff --git a/adapter/outboundgroup/urltest.go b/adapter/outboundgroup/urltest.go index 5b0d2a17..442494d9 100644 --- a/adapter/outboundgroup/urltest.go +++ b/adapter/outboundgroup/urltest.go @@ -96,25 +96,30 @@ func (u *URLTest) Unwrap(metadata *C.Metadata, touch bool) C.Proxy { } func (u *URLTest) fast(touch bool) C.Proxy { - elm, _, shared := u.fastSingle.Do(func() (C.Proxy, error) { - var s C.Proxy - proxies := u.GetProxies(touch) - fast := proxies[0] - if fast.Name() == u.selected { - s = fast + + proxies := u.GetProxies(touch) + if u.selected != "" { + for _, proxy := range proxies { + if !proxy.Alive() { + continue + } + if proxy.Name() == u.selected { + u.fastNode = proxy + return proxy + } } + } + + elm, _, shared := u.fastSingle.Do(func() (C.Proxy, error) { + fast := proxies[0] min := fast.LastDelay() fastNotExist := true for _, proxy := range proxies[1:] { - if u.fastNode != nil && proxy.Name() == u.fastNode.Name() { fastNotExist = false } - if proxy.Name() == u.selected { - s = proxy - } if !proxy.Alive() { continue } @@ -124,16 +129,12 @@ func (u *URLTest) fast(touch bool) C.Proxy { fast = proxy min = delay } + } // tolerance if u.fastNode == nil || fastNotExist || !u.fastNode.Alive() || u.fastNode.LastDelay() > fast.LastDelay()+u.tolerance { u.fastNode = fast } - if s != nil { - if s.Alive() && s.LastDelay() < fast.LastDelay()+u.tolerance { - u.fastNode = s - } - } return u.fastNode, nil }) if shared && touch { // a shared fastSingle.Do() may cause providers untouched, so we touch them again