From afe874f15a98dbd6a85008775bdbea5c2bc7bffc Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 6 Sep 2016 02:23:32 -0700 Subject: [PATCH] api: CopyObject pipe should be closed pro-actively upon error. (#2625) Fixes a deadlock reproduced while running s3verify during RemoveObject(). Previously held lock by GetObject() inside the go-routine was never relenquished. --- cmd/object-handlers.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/object-handlers.go b/cmd/object-handlers.go index fbaa7db9f..af08ce70c 100644 --- a/cmd/object-handlers.go +++ b/cmd/object-handlers.go @@ -334,10 +334,14 @@ func (api objectAPIHandlers) CopyObjectHandler(w http.ResponseWriter, r *http.Re // Create the object. md5Sum, err := api.ObjectAPI.PutObject(bucket, object, size, pipeReader, metadata) if err != nil { + // Close the this end of the pipe upon error in PutObject. + pipeReader.CloseWithError(err) errorIf(err, "Unable to create an object.") writeErrorResponse(w, r, toAPIErrorCode(err), r.URL.Path) return } + // Explicitly close the reader, before fetching object info. + pipeReader.Close() objInfo, err = api.ObjectAPI.GetObjectInfo(bucket, object) if err != nil { @@ -352,8 +356,6 @@ func (api objectAPIHandlers) CopyObjectHandler(w http.ResponseWriter, r *http.Re setCommonHeaders(w) // write success response. writeSuccessResponse(w, encodedSuccessResponse) - // Explicitly close the reader, to avoid fd leaks. - pipeReader.Close() if eventN.IsBucketNotificationSet(bucket) { // Notify object created event.