Skip to content

Commit

Permalink
Make sure to always release resources
Browse files Browse the repository at this point in the history
Make sure to always release resources in the event of timeout
  • Loading branch information
amezghal authored and erikdubbelboer committed Nov 28, 2018
1 parent 707bfb8 commit 80829ab
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions client.go
Expand Up @@ -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)
Expand All @@ -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
}
Expand Down

0 comments on commit 80829ab

Please sign in to comment.