Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wait for mpuid until got in waitForCreateMPU #502

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kungf
Copy link

@kungf kungf commented Mar 4, 2020

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.

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.
@kahing
Copy link
Owner

kahing commented Mar 17, 2020

sorry I don't understand the issue here or the change you are trying to make. does it address a real issue or a perceived code quality issue?

@kungf
Copy link
Author

kungf commented Mar 18, 2020

hi @kahing
In the code below,

  1. fh.mpuWG.Add(1)
  2. then go fh.mpuPart()
  3. if fh.mpuId is nil, then fh.mpuWG.Wait(), here will deadlock if it first mpuWG add(1) then wait() mpuWG to be zero, before Done() release
func (fh *FileHandle) uploadCurrentBuf(parallel bool) (err error) {
	err = fh.waitForCreateMPU()
        ......
	if parallel {
		fh.mpuWG.Add(1)
		go fh.mpuPart(buf, part, fh.nextWriteOffset)
                 /--- this is part of mpuPart func
	              if fh.mpuId == nil {
		              fh.mpuWG.Wait()
                ---/
	} else {
        ......
	}
	return
}

there is a simple test case:

package main
import (
	"fmt"
	"sync"
)

var wg sync.WaitGroup
func test() {
	wg.Wait()
	fmt.Println("test")
	wg.Done()
}

func main() {
	wg.Add(1)
	go test()
	wg.Wait()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants