From 35c695005f57cf49ff2084e2b83a0aa010fe12da Mon Sep 17 00:00:00 2001 From: Kris Date: Fri, 19 Aug 2016 11:04:54 -0700 Subject: [PATCH] Attempt to ensure entire resp body is read --- pkg/client/restclient/request.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/client/restclient/request.go b/pkg/client/restclient/request.go index dd1bbb35a53..1ec02b54f7e 100644 --- a/pkg/client/restclient/request.go +++ b/pkg/client/restclient/request.go @@ -821,9 +821,16 @@ func (r *Request) request(fn func(*http.Request, *http.Response)) error { } done := func() bool { - // ensure the response body is closed before we reconnect, so that we reuse the same - // TCP connection - defer resp.Body.Close() + // Ensure the response body is fully read and closed + // before we reconnect, so that we reuse the same TCP + // connection. + defer func() { + const maxBodySlurpSize = 2 << 10 + if resp.ContentLength <= maxBodySlurpSize { + io.Copy(ioutil.Discard, &io.LimitedReader{R: resp.Body, N: maxBodySlurpSize}) + } + resp.Body.Close() + }() retries++ if seconds, wait := checkWait(resp); wait && retries < maxRetries {