Fix: urltest get fastest node ehavior (#326)
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user