From 9ab1f25a472730277dc5ae9c20782f04cfd090f9 Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Tue, 10 Oct 2023 08:36:44 -0700 Subject: [PATCH] fix : PutObjectExtract data races (#18199) Several callers to putObjectTar may be fighting to set sc. Move the write out of the loop. Use static resp, and request elements. Fixes tests with -race: ``` WARNING: DATA RACE Read at 0x00c01cd680e0 by goroutine 691354: github.com/minio/minio/cmd.objectAPIHandlers.PutObjectExtractHandler.func1() e:/gopath/src/github.com/minio/minio/cmd/object-handlers.go:2130 +0x149 github.com/minio/minio/cmd.untar.func1() e:/gopath/src/github.com/minio/minio/cmd/untar.go:250 +0x2b6 github.com/minio/minio/cmd.untar.func8() e:/gopath/src/github.com/minio/minio/cmd/untar.go:261 +0xa4 Previous write at 0x00c01cd680e0 by goroutine 691352: github.com/minio/minio/cmd.objectAPIHandlers.PutObjectExtractHandler.func1() e:/gopath/src/github.com/minio/minio/cmd/object-handlers.go:2131 +0x15d github.com/minio/minio/cmd.untar.func1() e:/gopath/src/github.com/minio/minio/cmd/untar.go:250 +0x2b6 github.com/minio/minio/cmd.untar.func8() e:/gopath/src/github.com/minio/minio/cmd/untar.go:261 +0xa4 ``` --- cmd/object-handlers.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/cmd/object-handlers.go b/cmd/object-handlers.go index bf2118feb..719bcb7fb 100644 --- a/cmd/object-handlers.go +++ b/cmd/object-handlers.go @@ -2113,13 +2113,19 @@ func (api objectAPIHandlers) PutObjectExtractHandler(w http.ResponseWriter, r *h getObjectInfo = api.CacheAPI().GetObjectInfo } + // These are static for all objects extracted. + reqParams := extractReqParams(r) + respElements := map[string]string{ + "requestId": w.Header().Get(xhttp.AmzRequestID), + "nodeId": w.Header().Get(xhttp.AmzRequestHostID), + } + if sc == "" { + sc = storageclass.STANDARD + } + putObjectTar := func(reader io.Reader, info os.FileInfo, object string) error { size := info.Size() - if sc == "" { - sc = storageclass.STANDARD - } - metadata := map[string]string{ xhttp.AmzStorageClass: sc, // save same storage-class as incoming stream. } @@ -2247,8 +2253,8 @@ func (api objectAPIHandlers) PutObjectExtractHandler(w http.ResponseWriter, r *h EventName: event.ObjectCreatedPut, BucketName: bucket, Object: objInfo, - ReqParams: extractReqParams(r), - RespElements: extractRespElements(w), + ReqParams: reqParams, + RespElements: respElements, UserAgent: r.UserAgent(), Host: handlers.GetSourceIP(r), }