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

sync: WaitGroup behaves differently in Go 1.11 #28123

Closed
ryan-ju opened this issue Oct 10, 2018 · 4 comments
Closed

sync: WaitGroup behaves differently in Go 1.11 #28123

ryan-ju opened this issue Oct 10, 2018 · 4 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@ryan-ju
Copy link

ryan-ju commented Oct 10, 2018

What version of Go are you using (go version)?

go version go1.11.1 darwin/amd64

Does this issue reproduce with the latest release?

Yes, if 1.11.1 is still the latest release

What operating system and processor architecture are you using (go env)?

GOHOSTARCH="amd64"
GOHOSTOS="darwin"

What did you do?

https://goplay.space/#DhhSig-fDHM

What did you expect to see?

The code should run without errors.

The code works with Go 1.10.2

What did you see instead?

The code returned this:

panic: sync: negative WaitGroup counter

goroutine 59 [running]:
sync.(*WaitGroup).Add(0xc0003d0cb4, 0xffffffffffffffff)
	/usr/local/Cellar/go/1.11.1/libexec/src/sync/waitgroup.go:74 +0x137
sync.(*WaitGroup).Done(0xc0003d0cb4)
	/usr/local/Cellar/go/1.11.1/libexec/src/sync/waitgroup.go:99 +0x34
@zegl
Copy link
Contributor

zegl commented Oct 10, 2018

@ryan-ju Can you reproduce it yourself with that small example of yours?

I tried to reproduce it without success. Is there something missing from your example?

~ go version
go version go1.11.1 darwin/amd64
~ cat go-issue-28123.go
package main

import (
	"fmt"
	"sync"
)

type TestStruct struct {
	Wait sync.WaitGroup
}

func main() {
	w := sync.WaitGroup{}
	w.Add(1)
	t := &TestStruct{
		Wait: w,
	}

	t.Wait.Done()
	fmt.Println("Finished")
}

~ go run go-issue-28123.go
Finished

@zegl
Copy link
Contributor

zegl commented Oct 10, 2018

@gopherbot please add label waitingforinfo

@gopherbot gopherbot added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Oct 10, 2018
@ianlancetaylor ianlancetaylor changed the title sync.WaitGroup behaves differently in Go 1.11 sync: WaitGroup behaves differently in Go 1.11 Oct 10, 2018
@ryan-ju
Copy link
Author

ryan-ju commented Oct 10, 2018

@zegl This issue actually happens intermittently for me. I wrote a small bash to get some stats out:

#!/usr/bin/env bash

FAIL=0
SUCC=0
for (( i=0; i<=100; i++ )); do
  go run main2.go > /dev/null 2>&1
  status="$?"
  if [[ $status == 0 ]]; then
    SUCC=$((SUCC+1))
  else
    FAIL=$((FAIL+1))
  fi
  echo "run $i, status = $status"
done
echo "success = $SUCC, fail = $FAIL"

Result:

success = 63, fail = 38

About a third of the time it failed.

@ianlancetaylor ianlancetaylor added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Oct 10, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.12 milestone Oct 10, 2018
@ianlancetaylor
Copy link
Contributor

Your code is copying a sync.WaitGroup. You can't do that, as documented at https://golang.org/pkg/sync/#WaitGroup. If you run go vet on your package, you will get a warning. Closing because this is not a bug in Go.

@golang golang locked and limited conversation to collaborators Oct 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants