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 <cbennett@netflix.com>
This commit is contained in:
coryb 2021-07-10 18:22:02 -07:00
parent 51f2ce92fc
commit 894b6ae39b

View File

@ -190,6 +190,7 @@ func (p dockerPusher) push(ctx context.Context, desc ocispec.Descriptor, ref str
return nil, err return nil, err
} }
} }
defer resp.Body.Close()
switch resp.StatusCode { switch resp.StatusCode {
case http.StatusOK, http.StatusAccepted, http.StatusNoContent: 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 { if resp.err != nil {
return resp.err return resp.err
} }
defer resp.Response.Body.Close()
// 201 is specified return status, some registries return // 201 is specified return status, some registries return
// 200, 202 or 204. // 200, 202 or 204.