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

panic: sync: negative WaitGroup counter #109

Closed
jackleibest opened this issue Apr 28, 2023 · 7 comments
Closed

panic: sync: negative WaitGroup counter #109

jackleibest opened this issue Apr 28, 2023 · 7 comments

Comments

@jackleibest
Copy link

using the following codes:
var wg sync.WaitGroup
_, err := download.Boot().
URL(args.url).
Listener(func(event *download.Event) {
if event.Key == download.EventKeyProgress {
printProgress(event.Task, "downloading...")
}
if event.Key == download.EventKeyFinally {
var title string
if event.Err != nil {
title = "fail"
} else {
title = "complete"
}
printProgress(event.Task, title)
fmt.Println()
if event.Err != nil {
fmt.Printf("reason: %s", event.Err.Error())
} else {
fmt.Printf("saving path: %s", *args.dir)
}
wg.Done()
}
}).
Create(&base.Options{
Path: *args.dir,
Extra: http.OptsExtra{Connections: *args.connections},
})
if err != nil {
panic(err)
}
wg.Add(1)
wg.Wait()

and got the panic: sync: negative WaitGroup counter error:
panic: sync: negative WaitGroup counter

goroutine 29685 [running]:
sync.(*WaitGroup).Add(0x1b28c40?, 0x4?)
/usr/local/go/src/sync/waitgroup.go:62 +0xe5
sync.(*WaitGroup).Done(...)
/usr/local/go/src/sync/waitgroup.go:87
media.downloadFile.func1(0xc00021f590)
/root/apps/netstream/gstream/media/downloader.go:51 +0x257
github.com/GopeedLab/gopeed/pkg/download.(*Downloader).emit(0xc000136660, {0x126257b, 0x7}, 0xc00083c780, {0xc00089ef58?, 0x10fe500?, 0xc00083ca00?})
/root/apps/netstream/gstream/thirdparty/gopeed/pkg/download/downloader.go:410 +0xe5
github.com/GopeedLab/gopeed/pkg/download.(*Downloader).watch(0xc000136660, 0xc00083c780)
/root/apps/netstream/gstream/thirdparty/gopeed/pkg/download/downloader.go:483 +0x134
github.com/GopeedLab/gopeed/pkg/download.(*Downloader).Create.func2()
/root/apps/netstream/gstream/thirdparty/gopeed/pkg/download/downloader.go:285 +0x90
created by github.com/GopeedLab/gopeed/pkg/download.(*Downloader).Create
/root/apps/netstream/gstream/thirdparty/gopeed/pkg/download/downloader.go:279 +0x6f8

@monkeyWie
Copy link
Member

Fix in #110.

@jackleibest
Copy link
Author

jackleibest commented May 4, 2023

actually, I had put the wg.Add(1) in front of the beginning, like this, still got the promblem. it happens occasionally, especially in parallel downloading.

url:="https://xxxx.com/xxx.mp4"
connections :=8
var wg sync.WaitGroup
wg.Add(1)
_, err := download.Boot().URL(url).Listener(func(event *download.Event) {
	if event.Key == download.EventKeyProgress {
		//printProgress(event.Task, "downloading...", callbackProgress)
	}
	if event.Key == download.EventKeyFinally {
		//printProgress(event.Task, title, callbackProgress)
		fmt.Println()
		if event.Err != nil {
			log.Error("download failed: ", event.Err.Error())
		} else {
			log.Info("download success: ", url)
		}
		wg.Done()
	}
}).Create(&base.Options{
	Extra: http.OptsExtra{Connections: connections},
	DisableRename: true,
})
if err != nil {
	log.Error(err)
}
wg.Wait()

@monkeyWie
Copy link
Member

Can u provide gopeed version?

@jackleibest
Copy link
Author

using the latest repo.

@monkeyWie
Copy link
Member

There is no DisableRename option in the latest version. Did you add it yourself?

@jackleibest
Copy link
Author

yeah, becuase I wanna custom the save file name, so i disable the automatic rename, so sure it will not trigger the panic: sync: negative WaitGroup counter

@monkeyWie
Copy link
Member

I have tested your code and was unable to reproduce the issue. This exception is only triggered when calling wg.Add(1) after calling wg.Done(), but the code seem fine.

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

No branches or pull requests

2 participants