diff --git a/agent/dockerclient/dockerapi/docker_client.go b/agent/dockerclient/dockerapi/docker_client.go index e46a14b483f..ee7995b180a 100644 --- a/agent/dockerclient/dockerapi/docker_client.go +++ b/agent/dockerclient/dockerapi/docker_client.go @@ -1391,6 +1391,7 @@ func (dg *dockerGoClient) loadImage(ctx context.Context, reader io.Reader) error // flushing response reader if resp.Body != nil { + defer resp.Body.Close() _, err = io.Copy(ioutil.Discard, resp.Body) } return err diff --git a/agent/dockerclient/dockerapi/docker_client_test.go b/agent/dockerclient/dockerapi/docker_client_test.go index a03e72952d6..5df574f45e8 100644 --- a/agent/dockerclient/dockerapi/docker_client_test.go +++ b/agent/dockerclient/dockerapi/docker_client_test.go @@ -20,6 +20,7 @@ import ( "encoding/base64" "errors" "io" + "io/ioutil" "reflect" "strconv" "strings" @@ -1057,7 +1058,9 @@ func TestLoadImageHappyPath(t *testing.T) { mockDockerSDK, client, _, _, _, done := dockerClientSetup(t) defer done() - mockDockerSDK.EXPECT().ImageLoad(gomock.Any(), gomock.Any(), false).Return(types.ImageLoadResponse{}, nil) + mockDockerSDK.EXPECT().ImageLoad(gomock.Any(), gomock.Any(), false).Return(types.ImageLoadResponse{ + Body: ioutil.NopCloser(strings.NewReader("dummy load message")), + }, nil) ctx, cancel := context.WithCancel(context.TODO()) defer cancel()