From 8c079bf5bc7e3b0c30e3f250d1b1372a2b2818d4 Mon Sep 17 00:00:00 2001 From: Skyxim Date: Sat, 25 Jun 2022 09:16:28 +0800 Subject: [PATCH] fix: tcp concurrent force close when context done --- adapter/adapter.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/adapter/adapter.go b/adapter/adapter.go index e99cc0dd..1be877c7 100644 --- a/adapter/adapter.go +++ b/adapter/adapter.go @@ -151,6 +151,7 @@ func (p *Proxy) URLTest(ctx context.Context, url string) (t uint16, err error) { } client := http.Client{ + Timeout: 30 * time.Second, Transport: transport, CheckRedirect: func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse @@ -168,13 +169,12 @@ func (p *Proxy) URLTest(ctx context.Context, url string) (t uint16, err error) { _ = resp.Body.Close() if unifiedDelay { - start = time.Now() - respRepeat, err := client.Do(req) - if err != nil { - return 0, err + second := time.Now() + resp, err = client.Do(req) + if err == nil { + _ = resp.Body.Close() + start = second } - - _ = respRepeat.Body.Close() } t = uint16(time.Since(start) / time.Millisecond)