From 80829ab6ff1ba1ed41c7734d7a0d8936c70cf051 Mon Sep 17 00:00:00 2001 From: amezghal abdelilah Date: Tue, 30 Oct 2018 14:31:07 +0000 Subject: [PATCH] Make sure to always release resources Make sure to always release resources in the event of timeout --- client.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/client.go b/client.go index 7636229443..a19adf7804 100644 --- a/client.go +++ b/client.go @@ -971,12 +971,6 @@ func clientDoDeadline(req *Request, resp *Response, deadline time.Time, c client // usually continue execution on the host. go func() { ch <- c.Do(reqCopy, respCopy) - }() - - tc := acquireTimer(timeout) - var err error - select { - case err = <-ch: if resp != nil { respCopy.copyToSkipBody(resp) swapResponseBody(resp, respCopy) @@ -985,6 +979,13 @@ func clientDoDeadline(req *Request, resp *Response, deadline time.Time, c client ReleaseResponse(respCopy) ReleaseRequest(reqCopy) errorChPool.Put(chv) + }() + + tc := acquireTimer(timeout) + var err error + select { + case err = <-ch: + case <-tc.C: err = ErrTimeout }