mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
avoid data race access to uploadReaderToChunks.uploadErr (#3550)
avoid data race access to uploadErr https://github.com/seaweedfs/seaweedfs/issues/3549
This commit is contained in:
parent
903a06a160
commit
105702ebe0
|
@ -52,6 +52,7 @@ func (fs *FilerServer) uploadReaderToChunks(w http.ResponseWriter, r *http.Reque
|
||||||
var bytesBufferCounter int64
|
var bytesBufferCounter int64
|
||||||
bytesBufferLimitCond := sync.NewCond(new(sync.Mutex))
|
bytesBufferLimitCond := sync.NewCond(new(sync.Mutex))
|
||||||
var fileChunksLock sync.Mutex
|
var fileChunksLock sync.Mutex
|
||||||
|
var uploadErrLock sync.Mutex
|
||||||
for {
|
for {
|
||||||
|
|
||||||
// need to throttle used byte buffer
|
// need to throttle used byte buffer
|
||||||
|
@ -77,7 +78,9 @@ func (fs *FilerServer) uploadReaderToChunks(w http.ResponseWriter, r *http.Reque
|
||||||
bufPool.Put(bytesBuffer)
|
bufPool.Put(bytesBuffer)
|
||||||
atomic.AddInt64(&bytesBufferCounter, -1)
|
atomic.AddInt64(&bytesBufferCounter, -1)
|
||||||
bytesBufferLimitCond.Signal()
|
bytesBufferLimitCond.Signal()
|
||||||
|
uploadErrLock.Lock()
|
||||||
uploadErr = err
|
uploadErr = err
|
||||||
|
uploadErrLock.Unlock()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if chunkOffset == 0 && !isAppend {
|
if chunkOffset == 0 && !isAppend {
|
||||||
|
@ -105,8 +108,12 @@ func (fs *FilerServer) uploadReaderToChunks(w http.ResponseWriter, r *http.Reque
|
||||||
}()
|
}()
|
||||||
|
|
||||||
chunk, toChunkErr := fs.dataToChunk(fileName, contentType, bytesBuffer.Bytes(), offset, so)
|
chunk, toChunkErr := fs.dataToChunk(fileName, contentType, bytesBuffer.Bytes(), offset, so)
|
||||||
if uploadErr == nil && toChunkErr != nil {
|
if toChunkErr != nil {
|
||||||
uploadErr = toChunkErr
|
uploadErrLock.Lock()
|
||||||
|
if uploadErr == nil {
|
||||||
|
uploadErr = toChunkErr
|
||||||
|
}
|
||||||
|
uploadErrLock.Unlock()
|
||||||
}
|
}
|
||||||
if chunk != nil {
|
if chunk != nil {
|
||||||
fileChunksLock.Lock()
|
fileChunksLock.Lock()
|
||||||
|
|
Loading…
Reference in a new issue