From 109a76e1fc0ae147bd635647ad12a30c39a6d96f Mon Sep 17 00:00:00 2001 From: Skyxim Date: Sun, 19 Jun 2022 17:29:46 +0800 Subject: [PATCH] fix: url test http response not closed --- adapter/adapter.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/adapter/adapter.go b/adapter/adapter.go index b1867998..e99cc0dd 100644 --- a/adapter/adapter.go +++ b/adapter/adapter.go @@ -156,20 +156,27 @@ func (p *Proxy) URLTest(ctx context.Context, url string) (t uint16, err error) { return http.ErrUseLastResponse }, } + defer client.CloseIdleConnections() + resp, err := client.Do(req) + if err != nil { return } + _ = resp.Body.Close() + if unifiedDelay { start = time.Now() - resp, err = client.Do(req) + respRepeat, err := client.Do(req) if err != nil { - return + return 0, err } + + _ = respRepeat.Body.Close() } - _ = resp.Body.Close() + t = uint16(time.Since(start) / time.Millisecond) return }