From cb097e6b0a0132156a4df2e5cb65ecfbdbd8da08 Mon Sep 17 00:00:00 2001 From: Poorna Date: Tue, 21 Jun 2022 19:20:11 -0700 Subject: [PATCH] CopyObject: fix read/write err on closed pipe (#15135) Fixes: #15128 Regression from PR#14971 --- cmd/erasure-sets.go | 3 +++ cmd/object-handlers.go | 4 ---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/cmd/erasure-sets.go b/cmd/erasure-sets.go index 04976f3df..4eebd7fc4 100644 --- a/cmd/erasure-sets.go +++ b/cmd/erasure-sets.go @@ -1047,11 +1047,13 @@ func (s *erasureSets) CopyObject(ctx context.Context, srcBucket, srcObject, dstB // Version ID is set for the destination and source == destination version ID. // perform an in-place update. if dstOpts.VersionID != "" && srcOpts.VersionID == dstOpts.VersionID { + srcInfo.Reader.Close() // We are not interested in the reader stream at this point close it. return srcSet.CopyObject(ctx, srcBucket, srcObject, dstBucket, dstObject, srcInfo, srcOpts, dstOpts) } // Destination is not versioned and source version ID is empty // perform an in-place update. if !dstOpts.Versioned && srcOpts.VersionID == "" { + srcInfo.Reader.Close() // We are not interested in the reader stream at this point close it. return srcSet.CopyObject(ctx, srcBucket, srcObject, dstBucket, dstObject, srcInfo, srcOpts, dstOpts) } // CopyObject optimization where we don't create an entire copy @@ -1060,6 +1062,7 @@ func (s *erasureSets) CopyObject(ctx context.Context, srcBucket, srcObject, dstB // that we actually create a new dataDir for legacy objects. if dstOpts.Versioned && srcOpts.VersionID != dstOpts.VersionID && !srcInfo.Legacy { srcInfo.versionOnly = true + srcInfo.Reader.Close() // We are not interested in the reader stream at this point close it. return srcSet.CopyObject(ctx, srcBucket, srcObject, dstBucket, dstObject, srcInfo, srcOpts, dstOpts) } } diff --git a/cmd/object-handlers.go b/cmd/object-handlers.go index 70f09a6a8..2245c2219 100644 --- a/cmd/object-handlers.go +++ b/cmd/object-handlers.go @@ -1433,10 +1433,6 @@ func (api objectAPIHandlers) CopyObjectHandler(w http.ResponseWriter, r *http.Re srcInfo.metadataOnly = false } - if srcInfo.metadataOnly { - gr.Close() // We are not interested in the reader stream at this point close it. - } - // Check if x-amz-metadata-directive or x-amz-tagging-directive was not set to REPLACE and source, // destination are same objects. Apply this restriction also when // metadataOnly is true indicating that we are not overwriting the object.