From 894b6ae39b9266411d0d4e6325235390c06fc0ab Mon Sep 17 00:00:00 2001 From: coryb Date: Sat, 10 Jul 2021 18:22:02 -0700 Subject: [PATCH] Fix missing Body.Close() calls on push to docker remote Discovered this while using HTTP tracing via OpenTelemetry inside of buildkitd, where the trace spans were not being reported for the registry PUT http requests. The spans are only reported on the Close for the Body, after adding these Close calls, the spans are reported as expected. Signed-off-by: coryb --- remotes/docker/pusher.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/remotes/docker/pusher.go b/remotes/docker/pusher.go index 8028d1421..eae5a251d 100644 --- a/remotes/docker/pusher.go +++ b/remotes/docker/pusher.go @@ -190,6 +190,7 @@ func (p dockerPusher) push(ctx context.Context, desc ocispec.Descriptor, ref str return nil, err } } + defer resp.Body.Close() switch resp.StatusCode { case http.StatusOK, http.StatusAccepted, http.StatusNoContent: @@ -382,6 +383,7 @@ func (pw *pushWriter) Commit(ctx context.Context, size int64, expected digest.Di if resp.err != nil { return resp.err } + defer resp.Response.Body.Close() // 201 is specified return status, some registries return // 200, 202 or 204.