agiledragon / agiledragon/gomonkey

ApplyFuncSeq has DATA RACE issue

Ouverte
#120 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Go
Étoiles
2.3k
Forks
192
Merge moyen
1 j 6 h
PR mergées (30 j)
1

Description

```go
package playground_test

import (
"testing"

"github.com/agiledragon/gomonkey/v2"
"github.com/stretchr/testify/assert"
"golang.org/x/sync/errgroup"
)

func foo() int {
return 0
}

func run() error {
var eg errgroup.Group

eg.Go(func() error {
foo()
return nil
})

eg.Go(func() error {
foo()
return nil
})

if err := eg.Wait(); err != nil {
return err
}

return nil
}

func TestPlayground(t *testing.T) {
assert := assert.New(t)

patches := gomonkey.NewPatches()
defer patches.Reset()

patches.ApplyFuncSeq(foo, []gomonkey.OutputCell{
{
Values: gomonkey.Params{1},
},
{
Values: gomonkey.Params{2},
},
})

err := run()
assert.Nil(err)
}
```

run with `go test -race -gcflags=all=-l`, would get the following error
```
==================
WARNING: DATA RACE
Read at 0x00c000222d88 by goroutine 8:
github.com/agiledragon/gomonkey/v2.getDoubleFunc.func1()
/data00/home/liuqi.victor/go/pkg/mod/github.com/agiledragon/gomonkey/v2@v2.9.0/patch.go:304 +0xde
reflect.callReflect()
/data00/home/liuqi.victor/opt/go/src/reflect/value.go:770 +0x762
reflect.callReflect()
:1 +0x64
reflect.makeFuncStub()
/data00/home/liuqi.victor/opt/go/src/reflect/asm_amd64.s:47 +0x79
golang.org/x/sync/errgroup.(*Group).Go.func1()
/data00/home/liuqi.victor/go/pkg/mod/golang.org/x/sync@v0.1.0/errgroup/errgroup.go:75 +0x86

Previous write at 0x00c000222d88 by goroutine 9:
github.com/agiledragon/gomonkey/v2.getDoubleFunc.func1()
/data00/home/liuqi.victor/go/pkg/mod/github.com/agiledragon/gomonkey/v2@v2.9.0/patch.go:305 +0x108
reflect.callReflect()
/data00/home/liuqi.victor/opt/go/src/reflect/value.go:770 +0x762
reflect.callReflect()
:1 +0x64
reflect.makeFuncStub()
/data00/home/liuqi.victor/opt/go/src/reflect/asm_amd64.s:47 +0x79
golang.org/x/sync/errgroup.(*Group).Go.func1()
/data00/home/liuqi.victor/go/pkg/mod/golang.org/x/sync@v0.1.0/errgroup/errgroup.go:75 +0x86
```

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.