From c131764c348060ae6103c2a3f83b1b42e5ec04b0 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Mon, 5 Apr 2021 19:40:12 -0700 Subject: [PATCH] ensure error is sent back in channel fix https://github.com/chrislusf/seaweedfs/issues/1966 avoid shared readErr variable --- weed/server/filer_server_handlers_write_upload.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/weed/server/filer_server_handlers_write_upload.go b/weed/server/filer_server_handlers_write_upload.go index 28aad8c5a..03db942c6 100644 --- a/weed/server/filer_server_handlers_write_upload.go +++ b/weed/server/filer_server_handlers_write_upload.go @@ -57,26 +57,27 @@ func (fs *FilerServer) uploadReaderToChunks(w http.ResponseWriter, r *http.Reque var lock sync.Mutex readOffset := int64(0) var wg sync.WaitGroup - var readErr error - for readErr == nil { + for err == nil { wg.Add(1) request := func() { defer wg.Done() var localOffset int64 - var data []byte // read from the input lock.Lock() localOffset = readOffset limitedReader := io.LimitReader(partReader, int64(chunkSize)) - data, readErr = ioutil.ReadAll(limitedReader) + data, readErr := ioutil.ReadAll(limitedReader) readOffset += int64(len(data)) lock.Unlock() // handle read errors if readErr != nil { if readErr != io.EOF { + if err == nil { + err = readErr + } resultsChan <- &ChunkCreationResult{ err: readErr, } @@ -92,6 +93,9 @@ func (fs *FilerServer) uploadReaderToChunks(w http.ResponseWriter, r *http.Reque dataReader := util.NewBytesReader(data) fileId, uploadResult, uploadErr := fs.doCreateChunk(w, r, so, dataReader, fileName, contentType) if uploadErr != nil { + if err == nil { + err = uploadErr + } resultsChan <- &ChunkCreationResult{ err: uploadErr, }