From 3ea06f6697a209ec649cd14e661e25fc068571e6 Mon Sep 17 00:00:00 2001 From: kungf Date: Wed, 4 Mar 2020 17:11:46 +0800 Subject: [PATCH] wait for mpuid until got in waitForCreateMPU if mpuId is nil in mpuPart, will deadlock, because fh.mpuWG.Add(1) called before mpuPart, it can not wait itself until defer mpuWG.Done(). we can wait mpuid in waitForCreateMPU until got it. --- internal/file.go | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/internal/file.go b/internal/file.go index a2ccbaa7..6b7333b5 100644 --- a/internal/file.go +++ b/internal/file.go @@ -151,15 +151,6 @@ func (fh *FileHandle) mpuPart(buf *MBuf, part uint32, total int64) { fh.mpuWG.Done() }() - // maybe wait for CreateMultipartUpload - if fh.mpuId == nil { - fh.mpuWG.Wait() - // initMPU might have errored - if fh.mpuId == nil { - return - } - } - err := fh.mpuPartNoSpawn(buf, part, total, false) if err != nil { if fh.lastWriteError == nil { @@ -169,18 +160,20 @@ func (fh *FileHandle) mpuPart(buf *MBuf, part uint32, total int64) { } func (fh *FileHandle) waitForCreateMPU() (err error) { - if fh.mpuId == nil { + for { + if fh.mpuId != nil || err != nil { + return + } + fh.mu.Unlock() fh.initWrite() fh.mpuWG.Wait() // wait for initMPU fh.mu.Lock() if fh.lastWriteError != nil { - return fh.lastWriteError + err = fh.lastWriteError } } - - return } func (fh *FileHandle) partSize() uint64 {