ptrwaitgroup
ptrwaitgroup finds a func that passes sync.WaitGroup as a value instead of a pointer
Instruction
go install github.com/sivchari/ptrwaitgroup/cmd/ptrwaitgroup
Usage
package main
import (
"sync"
)
var globalWait sync.WaitGroup
func g(wg sync.WaitGroup) {
wg.Done()
}
func pg(wg *sync.WaitGroup) {
wg.Done()
}
func main() {
{
var wg sync.WaitGroup
a := 1
wg.Add(1)
go func(a int, wg sync.WaitGroup) { // want "`wg` of arg `2` is passed as a value. you must pass as a pointer. the goroutine will be deadlock!"
println(a)
wg.Done()
}(a, wg)
wg.Wait()
wg.Add(1)
go func(a int, wg *sync.WaitGroup) { // ok
println(a)
wg.Done()
}(a, &wg)
wg.Wait()
}
{
var wg sync.WaitGroup
wg.Add(2)
go g(wg) // want "`wg` of arg `1` is passed as a value. you must pass as a pointer. the goroutine will be deadlock!"
go pg(&wg) // ok
wg.Wait()
}
{
go g(globalWait) // ok
}
}
fish
go vet -vettool=(which ptrwaitgroup) ./...
./main.go:23:3: `wg` of arg `2` is passed as a value. you must pass as a pointer. the goroutine will be deadlock!
./main.go:40:3: `wg` of arg `1` is passed as a value. you must pass as a pointer. the goroutine will be deadlock!
bash
$ go vet -vettool=`which ptrwaitgroup` ./...
./main.go:23:3: `wg` of arg `2` is passed as a value. you must pass as a pointer. the goroutine will be deadlock!
./main.go:40:3: `wg` of arg `1` is passed as a value. you must pass as a pointer. the goroutine will be deadlock!
CI
CircleCI
- run:
name: Install ptrwaitgroup
command: go get github.com/sivchari/ptrwaitgroup
- run:
name: Run ptrwaitgroup
command: go vet -vettool=`which ptrwaitgroup` ./...
GitHub Actions
- name: Install ptrwaitgroup
run: go get github.com/sivchari/ptrwaitgroup
- name: Run ptrwaitgroup
run: go vet -vettool=`which ptrwaitgroup` ./...