Skip to content

Commit

Permalink
cleanup resources
Browse files Browse the repository at this point in the history
  • Loading branch information
amezghal authored and erikdubbelboer committed Nov 28, 2018
1 parent db09046 commit 92e4256
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions client.go
Expand Up @@ -969,10 +969,22 @@ func clientDoDeadline(req *Request, resp *Response, deadline time.Time, c client
// Without this 'hack' the load on slow host could exceed MaxConns*
// concurrent requests, since timed out requests on client side
// usually continue execution on the host.


cleanup := false
go func() {
errDo := c.Do(reqCopy, respCopy)
// cleanup
if cleanup {
ReleaseResponse(respCopy)
ReleaseRequest(reqCopy)
} else {
ch <- errDo
}
}()

tc := acquireTimer(timeout)
var err error
select {
case err = <-ch:
if resp != nil {
respCopy.copyToSkipBody(resp)
swapResponseBody(resp, respCopy)
Expand All @@ -981,15 +993,9 @@ func clientDoDeadline(req *Request, resp *Response, deadline time.Time, c client
ReleaseResponse(respCopy)
ReleaseRequest(reqCopy)
errorChPool.Put(chv)
ch <- errDo
}()

tc := acquireTimer(timeout)
var err error
select {
case err = <-ch:

case <-tc.C:
cleanup = true
errorChPool.Put(chv)
err = ErrTimeout
}
releaseTimer(tc)
Expand Down

0 comments on commit 92e4256

Please sign in to comment.