mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
ensure error is sent back in channel
fix https://github.com/chrislusf/seaweedfs/issues/1966 avoid shared readErr variable
This commit is contained in:
parent
0a9d76c9eb
commit
c131764c34
|
@ -57,26 +57,27 @@ func (fs *FilerServer) uploadReaderToChunks(w http.ResponseWriter, r *http.Reque
|
||||||
var lock sync.Mutex
|
var lock sync.Mutex
|
||||||
readOffset := int64(0)
|
readOffset := int64(0)
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
var readErr error
|
|
||||||
|
|
||||||
for readErr == nil {
|
for err == nil {
|
||||||
|
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
request := func() {
|
request := func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
var localOffset int64
|
var localOffset int64
|
||||||
var data []byte
|
|
||||||
// read from the input
|
// read from the input
|
||||||
lock.Lock()
|
lock.Lock()
|
||||||
localOffset = readOffset
|
localOffset = readOffset
|
||||||
limitedReader := io.LimitReader(partReader, int64(chunkSize))
|
limitedReader := io.LimitReader(partReader, int64(chunkSize))
|
||||||
data, readErr = ioutil.ReadAll(limitedReader)
|
data, readErr := ioutil.ReadAll(limitedReader)
|
||||||
readOffset += int64(len(data))
|
readOffset += int64(len(data))
|
||||||
lock.Unlock()
|
lock.Unlock()
|
||||||
// handle read errors
|
// handle read errors
|
||||||
if readErr != nil {
|
if readErr != nil {
|
||||||
if readErr != io.EOF {
|
if readErr != io.EOF {
|
||||||
|
if err == nil {
|
||||||
|
err = readErr
|
||||||
|
}
|
||||||
resultsChan <- &ChunkCreationResult{
|
resultsChan <- &ChunkCreationResult{
|
||||||
err: readErr,
|
err: readErr,
|
||||||
}
|
}
|
||||||
|
@ -92,6 +93,9 @@ func (fs *FilerServer) uploadReaderToChunks(w http.ResponseWriter, r *http.Reque
|
||||||
dataReader := util.NewBytesReader(data)
|
dataReader := util.NewBytesReader(data)
|
||||||
fileId, uploadResult, uploadErr := fs.doCreateChunk(w, r, so, dataReader, fileName, contentType)
|
fileId, uploadResult, uploadErr := fs.doCreateChunk(w, r, so, dataReader, fileName, contentType)
|
||||||
if uploadErr != nil {
|
if uploadErr != nil {
|
||||||
|
if err == nil {
|
||||||
|
err = uploadErr
|
||||||
|
}
|
||||||
resultsChan <- &ChunkCreationResult{
|
resultsChan <- &ChunkCreationResult{
|
||||||
err: uploadErr,
|
err: uploadErr,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue