diff --git a/adapter/adapter.go b/adapter/adapter.go index d1f37863c6..cd1b73733f 100644 --- a/adapter/adapter.go +++ b/adapter/adapter.go @@ -185,33 +185,22 @@ func (p *Proxy) URLTest(ctx context.Context, url string, expectedStatus utils.In if alive { record.Delay = t } - - p.alive.Store(alive) - p.history.Put(record) - if p.history.Len() > defaultHistoriesNum { - p.history.Pop() + if !satisfied { + alive = false } - state, ok := p.extra.Load(url) if !ok { state = &internalProxyState{ history: queue.New[C.DelayHistory](defaultHistoriesNum), - alive: atomic.NewBool(true), + alive: atomic.NewBool(alive), } p.extra.Store(url, state) } - - if !satisfied { - record.Delay = 0 - alive = false - } - state.alive.Store(alive) state.history.Put(record) if state.history.Len() > defaultHistoriesNum { state.history.Pop() } - }() unifiedDelay := UnifiedDelay.Load() @@ -285,6 +274,9 @@ func (p *Proxy) URLTest(ctx context.Context, url string, expectedStatus utils.In satisfied = resp != nil && (expectedStatus == nil || expectedStatus.Check(uint16(resp.StatusCode))) t = uint16(time.Since(start) / time.Millisecond) + if !satisfied { + err = fmt.Errorf("failed by unsatisfied!status:%d", resp.StatusCode) + } return } diff --git a/hub/route/proxies.go b/hub/route/proxies.go index ba4e03f902..8597f5e33f 100644 --- a/hub/route/proxies.go +++ b/hub/route/proxies.go @@ -135,7 +135,10 @@ func getProxyDelay(w http.ResponseWriter, r *http.Request) { if err != nil || delay == 0 { render.Status(r, http.StatusServiceUnavailable) if err != nil && delay != 0 { - render.JSON(w, r, err) + render.JSON(w, r, render.M{ + "delay": delay, + "error": err.Error(), + }) } else { render.JSON(w, r, newError("An error occurred in the delay test")) }