From 79564656eb525ec33308d11ec5b6184d415c7a91 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 24 Mar 2021 09:05:03 -0700 Subject: [PATCH] xl: CreateFile shouldn't prematurely timeout (#11878) For large objects taking more than '3 minutes' response times in a single PUT operation can timeout prematurely as 'ResponseHeader' timeout hits for 3 minutes. Avoid this by keeping the connection active during CreateFile phase. --- cmd/storage-rest-client.go | 7 ++++++- cmd/storage-rest-server.go | 7 +++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/cmd/storage-rest-client.go b/cmd/storage-rest-client.go index a3a72f800..70b9c60ac 100644 --- a/cmd/storage-rest-client.go +++ b/cmd/storage-rest-client.go @@ -337,7 +337,12 @@ func (client *storageRESTClient) CreateFile(ctx context.Context, volume, path st values.Set(storageRESTFilePath, path) values.Set(storageRESTLength, strconv.Itoa(int(size))) respBody, err := client.call(ctx, storageRESTMethodCreateFile, values, ioutil.NopCloser(reader), size) - defer http.DrainBody(respBody) + if err != nil { + return err + } + waitReader, err := waitForHTTPResponse(respBody) + defer http.DrainBody(ioutil.NopCloser(waitReader)) + defer respBody.Close() return err } diff --git a/cmd/storage-rest-server.go b/cmd/storage-rest-server.go index baf3e9070..b161c5c86 100644 --- a/cmd/storage-rest-server.go +++ b/cmd/storage-rest-server.go @@ -287,10 +287,9 @@ func (s *storageRESTServer) CreateFileHandler(w http.ResponseWriter, r *http.Req s.writeErrorResponse(w, err) return } - err = s.storage.CreateFile(r.Context(), volume, filePath, int64(fileSize), r.Body) - if err != nil { - s.writeErrorResponse(w, err) - } + + done := keepHTTPResponseAlive(w) + done(s.storage.CreateFile(r.Context(), volume, filePath, int64(fileSize), r.Body)) } // DeleteVersion delete updated metadata.