Fix: urltest get fastest node ehavior (#326)

This commit is contained in:
comwrg
2019-10-12 23:29:00 +08:00
committed by Dreamacro
parent 4cd8b6f24f
commit 0cdc40beb3
5 changed files with 75 additions and 29 deletions

View File

@ -9,7 +9,6 @@ import (
"time"
A "github.com/Dreamacro/clash/adapters/outbound"
"github.com/Dreamacro/clash/common/picker"
C "github.com/Dreamacro/clash/constant"
T "github.com/Dreamacro/clash/tunnel"
@ -111,21 +110,17 @@ func getProxyDelay(w http.ResponseWriter, r *http.Request) {
proxy := r.Context().Value(CtxKeyProxy).(C.Proxy)
picker, ctx, cancel := picker.WithTimeout(context.Background(), time.Millisecond*time.Duration(timeout))
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*time.Duration(timeout))
defer cancel()
picker.Go(func() (interface{}, error) {
return proxy.URLTest(ctx, url)
})
elm := picker.Wait()
if elm == nil {
delay, err := proxy.URLTest(ctx, url)
if ctx.Err() != nil {
render.Status(r, http.StatusGatewayTimeout)
render.JSON(w, r, ErrRequestTimeout)
return
}
delay := elm.(uint16)
if delay == 0 {
if err != nil || delay == 0 {
render.Status(r, http.StatusServiceUnavailable)
render.JSON(w, r, newError("An error occurred in the delay test"))
return