bytedance / mockey

a simple and easy-to-use golang mock library
Apache License 2.0
556 stars 22 forks source link

The error `runtime: checkdead: find g 19 in status 1` occurred when run go test #32

Closed 201907 closed 9 months ago

201907 commented 10 months ago

Describe the bug

When running “go test” on multiple test files in different packages concurrently, deadlock may occur in windows system.

To Reproduce

Steps to reproduce the behavior:

  1. Create a folder “test1” with files: “main_test.go".
    
    import (
    "fmt"
    "testing"
    "time"
    . "github.com/bytedance/mockey"
    . "github.com/smartystreets/goconvey/convey"
    )

func Foo(in string) string { return in }

type A struct{}

func (a A) Foo(in string) string { return in }

var Bar = 0

func TestMockXXX(t testing.T) { PatchConvey("TestMockXXX", t, func() { Mock(Foo).Return("c").Build() // mock function Mock(A.Foo).Return("c").Build() // mock method MockValue(&Bar).To(1) // mock variable time.Sleep(5 time.Second) So(Foo("a"), ShouldEqual, "c") // assert Foo is mocked So(new(A).Foo("b"), ShouldEqual, "c") // assert A.Foo is mocked So(Bar, ShouldEqual, 1) // assert Bar is mocked }) // mock is released automatically outside PatchConvey fmt.Println(Foo("a")) // a fmt.Println(new(A).Foo("b")) // b fmt.Println(Bar) // 0 }


2. Copy the test1 folder 15 times.
3. CD to the parent folder of “test1” and execute the following command: `go test -gcflags="all=-l -N" -p 1 -v -cover -covermode count -coverprofile cover.out ./...`
4. The error `runtime: checkdead: find g 19 in status 1` occurred.

**Mockey version:**

github.com/bytedance/mockey v1.2.4

**Environment:**

set GOVERSION=go1.20.1
set GCCGO=gccgo
set GOAMD64=v1
201907 commented 10 months ago

this is the logs

=== RUN   TestMockXXX

  TestMockXXX ...

3 total assertions

a
b
0
--- PASS: TestMockXXX (5.00s)
PASS
coverage: [no statements]
ok      main/test1       5.355s  coverage: [no statements]
=== RUN   TestMockXXX

  TestMockXXX ...runtime: checkdead: find g 19 in status 1
fatal error: checkdead: runnable g

runtime stack:
runtime.throw({0x8f3b21?, 0x5cd800?})
        C:/Users/zuosicheng/.g/go/src/runtime/panic.go:1047 +0x65 fp=0x83891ff648 sp=0x83891ff618 pc=0x601165
runtime.checkdead.func1(0xc0000849c0)
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:5216 +0xe5 fp=0x83891ff680 sp=0x83891ff648 pc=0x60e385
runtime.forEachG(0x83891ff700)
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:591 +0x58 fp=0x83891ff6b0 sp=0x83891ff680 pc=0x604758
runtime.checkdead()
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:5203 +0xf7 fp=0x83891ff720 sp=0x83891ff6b0 pc=0x60e077
runtime.mput(0xa6f400)
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:5696 +0x50 fp=0x83891ff740 sp=0x83891ff720 pc=0x60f670
runtime.stopm()
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:2332 +0x65 fp=0x83891ff768 sp=0x83891ff740 pc=0x607865
runtime.findRunnable()
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:3007 +0x3c fp=0x83891ff888 sp=0x83891ff768 pc=0x60841c
runtime.schedule()
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:3360 +0xc5 fp=0x83891ff8c0 sp=0x83891ff888 pc=0x609ba5
runtime.park_m(0xc0000849c0?)
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:3511 +0x10d fp=0x83891ff8f0 sp=0x83891ff8c0 pc=0x60a10d
runtime.mcall()
        C:/Users/zuosicheng/.g/go/src/runtime/asm_amd64.s:452 +0x48 fp=0x83891ff900 sp=0x83891ff8f0 pc=0x633808

goroutine 1 [chan receive]:
runtime.gopark(0x902088, 0xc0000fc0c8, 0xe, 0x17, 0x2)
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:381 +0xfd fp=0xc0000c9428 sp=0xc0000c93f8 pc=0x603bfd
runtime.chanrecv(0xc0000fc070, 0xc0000c9526, 0x1)
        C:/Users/zuosicheng/.g/go/src/runtime/chan.go:583 +0x31e fp=0xc0000c94b8 sp=0xc0000c9428 pc=0x5c78de
runtime.chanrecv1(0xa6e800?, 0x8a8c80?)
        C:/Users/zuosicheng/.g/go/src/runtime/chan.go:442 +0x18 fp=0xc0000c94e0 sp=0xc0000c94b8 pc=0x5c7558
testing.(*T).Run(0xc000084820, {0x8efe9f, 0xb}, 0x901ef8)
        C:/Users/zuosicheng/.g/go/src/testing/testing.go:1630 +0x7cb fp=0xc0000c96d8 sp=0xc0000c94e0 pc=0x7afa2b
testing.runTests.func1(0xc000084680)
        C:/Users/zuosicheng/.g/go/src/testing/testing.go:2036 +0xba fp=0xc0000c9770 sp=0xc0000c96d8 pc=0x7b34ba
testing.tRunner(0xc000084680, 0xc0000c9980)
        C:/Users/zuosicheng/.g/go/src/testing/testing.go:1576 +0x1ca fp=0xc0000c9888 sp=0xc0000c9770 pc=0x7ae0ca
testing.runTests(0xc00009a0a8, {0xa61ec0, 0x1, 0x1}, {0xc12d3fbb9495252c, 0x8bb3261c9d, 0xa6eba0})
        C:/Users/zuosicheng/.g/go/src/testing/testing.go:2034 +0x47d fp=0xc0000c99b0 sp=0xc0000c9888 pc=0x7b32dd
testing.(*M).Run(0xc00009e140)
        C:/Users/zuosicheng/.g/go/src/testing/testing.go:1906 +0xb8e fp=0xc0000c9ef0 sp=0xc0000c99b0 pc=0x7b0e6e
main.main()
        _testmain.go:78 +0xd8 fp=0xc0000c9f80 sp=0xc0000c9ef0 pc=0x88e3d8
runtime.main()
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:250 +0x1be fp=0xc0000c9fe0 sp=0xc0000c9f80 pc=0x60377e
runtime.goexit()
        C:/Users/zuosicheng/.g/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc0000c9fe8 sp=0xc0000c9fe0 pc=0x635b01

goroutine 2 [force gc (idle)]:
runtime.gopark(0x902298, 0xa6e540, 0x11, 0x14, 0x1)
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:381 +0xfd fp=0xc00004df88 sp=0xc00004df58 pc=0x603bfd
runtime.goparkunlock(0x0?, 0x0?, 0x0?, 0x0?)
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:387 +0x2a fp=0xc00004dfb8 sp=0xc00004df88 pc=0x603c8a
runtime.forcegchelper()
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:305 +0xb0 fp=0xc00004dfe0 sp=0xc00004dfb8 pc=0x6039d0
runtime.goexit()
        C:/Users/zuosicheng/.g/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc00004dfe8 sp=0xc00004dfe0 pc=0x635b01
created by runtime.init.6
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:293 +0x25

goroutine 3 [GC sweep wait]:
runtime.gopark(0x902298, 0xa6e9e0, 0xc, 0x14, 0x1)
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:381 +0xfd fp=0xc00004ff58 sp=0xc00004ff28 pc=0x603bfd
runtime.goparkunlock(0x0?, 0x0?, 0x0?, 0x0?)
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:387 +0x2a fp=0xc00004ff88 sp=0xc00004ff58 pc=0x603c8a
runtime.bgsweep(0x0?)
        C:/Users/zuosicheng/.g/go/src/runtime/mgcsweep.go:278 +0x98 fp=0xc00004ffc8 sp=0xc00004ff88 pc=0x5e8f78
runtime.gcenable.func1()
        C:/Users/zuosicheng/.g/go/src/runtime/mgc.go:178 +0x26 fp=0xc00004ffe0 sp=0xc00004ffc8 pc=0x5dd386
runtime.goexit()
        C:/Users/zuosicheng/.g/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc00004ffe8 sp=0xc00004ffe0 pc=0x635b01
created by runtime.gcenable
        C:/Users/zuosicheng/.g/go/src/runtime/mgc.go:178 +0x6b

goroutine 4 [GC scavenge wait]:
runtime.gopark(0x902298, 0xa6eca0, 0xd, 0x14, 0x2)
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:381 +0xfd fp=0xc00005ff48 sp=0xc00005ff18 pc=0x603bfd
runtime.goparkunlock(0x917128?, 0x1?, 0x0?, 0x0?)
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:387 +0x2a fp=0xc00005ff78 sp=0xc00005ff48 pc=0x603c8a
runtime.(*scavengerState).park(0xa6eca0)
        C:/Users/zuosicheng/.g/go/src/runtime/mgcscavenge.go:400 +0x4b fp=0xc00005ffa0 sp=0xc00005ff78 pc=0x5e6a2b
runtime.bgscavenge(0x0?)
        C:/Users/zuosicheng/.g/go/src/runtime/mgcscavenge.go:628 +0x45 fp=0xc00005ffc8 sp=0xc00005ffa0 pc=0x5e7005
runtime.gcenable.func2()
        C:/Users/zuosicheng/.g/go/src/runtime/mgc.go:179 +0x26 fp=0xc00005ffe0 sp=0xc00005ffc8 pc=0x5dd326
runtime.goexit()
        C:/Users/zuosicheng/.g/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc00005ffe8 sp=0xc00005ffe0 pc=0x635b01
created by runtime.gcenable
        C:/Users/zuosicheng/.g/go/src/runtime/mgc.go:179 +0xaa

goroutine 18 [finalizer wait]:
runtime.gopark(0x9020f0, 0xac3c30, 0x10, 0x14, 0x1)
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:381 +0xfd fp=0xc000051e28 sp=0xc000051df8 pc=0x603bfd
runtime.runfinq()
        C:/Users/zuosicheng/.g/go/src/runtime/mfinal.go:193 +0x107 fp=0xc000051fe0 sp=0xc000051e28 pc=0x5dc3e7
runtime.goexit()
        C:/Users/zuosicheng/.g/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc000051fe8 sp=0xc000051fe0 pc=0x635b01
created by runtime.createfing
        C:/Users/zuosicheng/.g/go/src/runtime/mfinal.go:163 +0x50

goroutine 19 [runnable, locked to thread]:
runtime.cgocall(0x6374a0, 0xc000054ec0)
        C:/Users/zuosicheng/.g/go/src/runtime/cgocall.go:157 +0x4a fp=0xc00010c588 sp=0xc00010c550 pc=0x5c56ca
syscall.SyscallN(0x7ffc695dab30, {0xc0000d22a0?, 0x4, 0x0?})
        C:/Users/zuosicheng/.g/go/src/runtime/syscall_windows.go:557 +0x12e fp=0xc00010c610 sp=0xc00010c588 pc=0x6326ce
syscall.(*Proc).Call(0xc0000a0540, {0xc0000d22a0, 0x4, 0x4})
        C:/Users/zuosicheng/.g/go/src/syscall/dll_windows.go:190 +0x8d fp=0xc00010c6a0 sp=0xc00010c610 pc=0x6a6ecd
syscall.(*LazyProc).Call(0xc0000bc8a0, {0xc0000d22a0, 0x4, 0x4})
        C:/Users/zuosicheng/.g/go/src/syscall/dll_windows.go:310 +0xa5 fp=0xc00010c738 sp=0xc00010c6a0 pc=0x6a7985
github.com/bytedance/mockey/internal/monkey/mem/prot.virtualProtect(0x88d000, 0x1000, 0x40, 0xc0000a6560)
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/bytedance/mockey@v1.2.4/internal/monkey/mem/prot/protect_windows.go:46 +0xe5 fp=0xc00010c7e0 sp=0xc00010c738 pc=0x877565      
github.com/bytedance/mockey/internal/monkey/mem/prot.mProtectPage(0x88d000, 0x40)
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/bytedance/mockey@v1.2.4/internal/monkey/mem/prot/protect_windows.go:42 +0xa5 fp=0xc00010c868 sp=0xc00010c7e0 pc=0x877425      
github.com/bytedance/mockey/internal/monkey/mem/prot.MProtectRWX(0x88d540)
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/bytedance/mockey@v1.2.4/internal/monkey/mem/prot/protect_windows.go:33 +0x38 fp=0xc00010c8b0 sp=0xc00010c868 pc=0x877298      
github.com/bytedance/mockey/internal/monkey/mem.Write(0x88d540, {0x1aa693a0000, 0xe, 0x1000})
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/bytedance/mockey@v1.2.4/internal/monkey/mem/write_windows.go:25 +0x59 fp=0xc00010c958 sp=0xc00010c8b0 pc=0x885199
github.com/bytedance/mockey/internal/monkey/mem.WriteWithSTW(0x88d540, {0x1aa693a0000, 0xe, 0x1000})
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/bytedance/mockey@v1.2.4/internal/monkey/mem/write.go:29 +0x94 fp=0xc00010ca28 sp=0xc00010c958 pc=0x884ff4
github.com/bytedance/mockey/internal/monkey.(*Patch).Unpatch(0xc0000bcf00)
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/bytedance/mockey@v1.2.4/internal/monkey/patch.go:38 +0x65 fp=0xc00010ca98 sp=0xc00010ca28 pc=0x885345
github.com/bytedance/mockey.(*Mocker).UnPatch(0xc00009c9c0)
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/bytedance/mockey@v1.2.4/mock.go:273 +0xe7 fp=0xc00010cb48 sp=0xc00010ca98 pc=0x889d27
github.com/bytedance/mockey.(*Mocker).unPatch(0xc00009c9c0)
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/bytedance/mockey@v1.2.4/mock.go:369 +0x1e fp=0xc00010cb60 sp=0xc00010cb48 pc=0x88abbe
github.com/bytedance/mockey.PatchConvey.func1.1()
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/bytedance/mockey@v1.2.4/convey.go:39 +0xc3 fp=0xc00010cc10 sp=0xc00010cb60 pc=0x88cee3
runtime.deferreturn()
        C:/Users/zuosicheng/.g/go/src/runtime/panic.go:476 +0x33 fp=0xc00010cc50 sp=0xc00010cc10 pc=0x5ffc33
github.com/bytedance/mockey.PatchConvey.func1({0xac3d38, 0x0, 0x0})
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/bytedance/mockey@v1.2.4/convey.go:43 +0x19a fp=0xc00010cd40 sp=0xc00010cc50 pc=0x88661a
reflect.callReflect(0xc0000bcb40, 0xc0000914e8, 0xc00010d3c0, 0xc00010d3c8)
        C:/Users/zuosicheng/.g/go/src/reflect/value.go:772 +0x6ab fp=0xc00010d370 sp=0xc00010cd40 pc=0x687ccb
reflect.callReflect(0xc0000bcb40, 0xc0000914e8, 0xc0000913c0, 0xc0000913c8)
        <autogenerated>:1 +0x50 fp=0xc00010d3a0 sp=0xc00010d370 pc=0x6a15d0
reflect.makeFuncStub()
        C:/Users/zuosicheng/.g/go/src/reflect/asm_amd64.s:47 +0x7f fp=0xc00010d4e8 sp=0xc00010d3a0 pc=0x69907f
github.com/smartystreets/goconvey/convey.parseAction.func1({0xc00009a120, 0xc0000bccc0})
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/smartystreets/goconvey@v1.6.4/convey/discovery.go:80 +0x22 fp=0xc00010d500 sp=0xc00010d4e8 pc=0x876042
github.com/smartystreets/goconvey/convey.(*context).conveyInner(0xc0000dc0c0, {0x8efe9f, 0xb}, 0xc000088800)
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/smartystreets/goconvey@v1.6.4/convey/context.go:261 +0x2a3 fp=0xc00010d6e8 sp=0xc00010d500 pc=0x8746c3
github.com/smartystreets/goconvey/convey.rootConvey.func1()
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/smartystreets/goconvey@v1.6.4/convey/context.go:110 +0x1b4 fp=0xc00010d7f0 sp=0xc00010d6e8 pc=0x873174
github.com/jtolds/gls.(*ContextManager).SetValues.func1(0x0)
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/jtolds/gls@v4.20.0+incompatible/context.go:97 +0x5bc fp=0xc00010da10 sp=0xc00010d7f0 pc=0x86939c
github.com/jtolds/gls.EnsureGoroutineId.func1()
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/jtolds/gls@v4.20.0+incompatible/gid.go:24 +0x2e fp=0xc00010da38 sp=0xc00010da10 pc=0x869b4e
github.com/jtolds/gls._m(0x0, 0xc00009a150)
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/jtolds/gls@v4.20.0+incompatible/stack_tags.go:108 +0x2f fp=0xc00010da58 sp=0xc00010da38 pc=0x86a8af
github.com/jtolds/gls.github_com_jtolds_gls_markS(0x0, 0xc00009a150)
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/jtolds/gls@v4.20.0+incompatible/stack_tags.go:56 +0x25 fp=0xc00010da78 sp=0xc00010da58 pc=0x86a245
github.com/jtolds/gls.addStackTag(0x0, 0xc00009a150)
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/jtolds/gls@v4.20.0+incompatible/stack_tags.go:49 +0x2c fp=0xc00010da98 sp=0xc00010da78 pc=0x86a1ec
github.com/jtolds/gls.EnsureGoroutineId(0xc0000bcc60)
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/jtolds/gls@v4.20.0+incompatible/gid.go:24 +0x19e fp=0xc00010db60 sp=0xc00010da98 pc=0x869ade
github.com/jtolds/gls.(*ContextManager).SetValues(0xc0000885b0, 0xc0000bcc00, 0xc0000a04a0)
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/jtolds/gls@v4.20.0+incompatible/context.go:63 +0x1fe fp=0xc00010dba8 sp=0xc00010db60 pc=0x868d9e
github.com/smartystreets/goconvey/convey.rootConvey({0xc000091e58, 0x3, 0x3})
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/smartystreets/goconvey@v1.6.4/convey/context.go:105 +0x36d fp=0xc00010dc70 sp=0xc00010dba8 pc=0x872f6d
github.com/smartystreets/goconvey/convey.Convey({0xc000091e58, 0x3, 0x3})
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/smartystreets/goconvey@v1.6.4/convey/doc.go:75 +0x5e fp=0xc00010dca8 sp=0xc00010dc70 pc=0x87629e
github.com/bytedance/mockey.PatchConvey({0xc000091e58, 0x3, 0x3})
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/bytedance/mockey@v1.2.4/convey.go:48 +0x251 fp=0xc00010dd70 sp=0xc00010dca8 pc=0x886431
main/test10.TestMockXXX(0xc000084820)
        C:/work/demo/golang_demo/test10/main_test.go:23 +0x112 fp=0xc00010de98 sp=0xc00010dd70 pc=0x88d6d2
testing.tRunner(0xc000084820, 0x901ef8)
        C:/Users/zuosicheng/.g/go/src/testing/testing.go:1576 +0x1ca fp=0xc00010dfb0 sp=0xc00010de98 pc=0x7ae0ca
testing.(*T).Run.func1()
        C:/Users/zuosicheng/.g/go/src/testing/testing.go:1629 +0x39 fp=0xc00010dfe0 sp=0xc00010dfb0 pc=0x7afc59
runtime.goexit()
        C:/Users/zuosicheng/.g/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc00010dfe8 sp=0xc00010dfe0 pc=0x635b01
created by testing.(*T).Run
        C:/Users/zuosicheng/.g/go/src/testing/testing.go:1629 +0x7a6
FAIL    main/test10     600.366s
=== RUN   TestMockXXX

  TestMockXXX ...

3 total assertions

a
b
0
--- PASS: TestMockXXX (5.00s)
PASS
coverage: [no statements]
ok      main/test11     5.367s  coverage: [no statements]
=== RUN   TestMockXXX

  TestMockXXX ...

3 total assertions

a
b
0
--- PASS: TestMockXXX (5.00s)
PASS
coverage: [no statements]
ok      main/test12     5.362s  coverage: [no statements]
=== RUN   TestMockXXX

  TestMockXXX ...

3 total assertions

a
b
0
--- PASS: TestMockXXX (5.00s)
PASS
coverage: [no statements]
ok      main/test13     5.374s  coverage: [no statements]
=== RUN   TestMockXXX

  TestMockXXX ...

3 total assertions

a
b
0
--- PASS: TestMockXXX (5.00s)
PASS
coverage: [no statements]
ok      main/test14     5.498s  coverage: [no statements]
=== RUN   TestMockXXX

  TestMockXXX ...

3 total assertions

a
b
0
--- PASS: TestMockXXX (5.00s)
PASS
coverage: [no statements]
ok      main/test15     5.339s  coverage: [no statements]
=== RUN   TestMockXXX

  TestMockXXX ...

3 total assertions

a
b
0
--- PASS: TestMockXXX (5.00s)
PASS
coverage: [no statements]
ok      main/test16     5.393s  coverage: [no statements]
=== RUN   TestMockXXX

  TestMockXXX ...

3 total assertions

a
b
0
--- PASS: TestMockXXX (5.00s)
PASS
coverage: [no statements]
ok      main/test2      5.316s  coverage: [no statements]
=== RUN   TestMockXXX

  TestMockXXX ...

3 total assertions

a
b
0
--- PASS: TestMockXXX (5.00s)
PASS
coverage: [no statements]
ok      main/test3      5.329s  coverage: [no statements]
=== RUN   TestMockXXX

  TestMockXXX ...runtime: checkdead: find g 6 in status 1
fatal error: checkdead: runnable g

runtime stack:
runtime.throw({0x5b3b20?, 0x28d800?})
        C:/Users/zuosicheng/.g/go/src/runtime/panic.go:1047 +0x65 fp=0xdb89dff828 sp=0xdb89dff7f8 pc=0x2c1165
runtime.checkdead.func1(0xc00004b6c0)
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:5216 +0xe5 fp=0xdb89dff860 sp=0xdb89dff828 pc=0x2ce385
runtime.forEachG(0xdb89dff8e0)
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:591 +0x58 fp=0xdb89dff890 sp=0xdb89dff860 pc=0x2c4758
runtime.checkdead()
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:5203 +0xf7 fp=0xdb89dff900 sp=0xdb89dff890 pc=0x2ce077
runtime.mput(0x72f400)
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:5696 +0x50 fp=0xdb89dff920 sp=0xdb89dff900 pc=0x2cf670
runtime.stopm()
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:2332 +0x65 fp=0xdb89dff948 sp=0xdb89dff920 pc=0x2c7865
runtime.findRunnable()
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:3007 +0x3c fp=0xdb89dffa68 sp=0xdb89dff948 pc=0x2c841c
runtime.schedule()
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:3360 +0xc5 fp=0xdb89dffaa0 sp=0xdb89dffa68 pc=0x2c9ba5
runtime.park_m(0xc00004b6c0?)
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:3511 +0x10d fp=0xdb89dffad0 sp=0xdb89dffaa0 pc=0x2ca10d
runtime.mcall()
        C:/Users/zuosicheng/.g/go/src/runtime/asm_amd64.s:452 +0x48 fp=0xdb89dffae0 sp=0xdb89dffad0 pc=0x2f3808

goroutine 1 [chan receive]:
runtime.gopark(0x5c2088, 0xc00001e1a8, 0xe, 0x17, 0x2)
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:381 +0xfd fp=0xc000115428 sp=0xc0001153f8 pc=0x2c3bfd
runtime.chanrecv(0xc00001e150, 0xc000115526, 0x1)
        C:/Users/zuosicheng/.g/go/src/runtime/chan.go:583 +0x31e fp=0xc0001154b8 sp=0xc000115428 pc=0x2878de
runtime.chanrecv1(0x72e800?, 0x568c80?)
        C:/Users/zuosicheng/.g/go/src/runtime/chan.go:442 +0x18 fp=0xc0001154e0 sp=0xc0001154b8 pc=0x287558
testing.(*T).Run(0xc00004b520, {0x5afea9, 0xb}, 0x5c1ef8)
        C:/Users/zuosicheng/.g/go/src/testing/testing.go:1630 +0x7cb fp=0xc0001156d8 sp=0xc0001154e0 pc=0x46fa2b
testing.runTests.func1(0xc00004b380)
        C:/Users/zuosicheng/.g/go/src/testing/testing.go:2036 +0xba fp=0xc000115770 sp=0xc0001156d8 pc=0x4734ba
testing.tRunner(0xc00004b380, 0xc000115980)
        C:/Users/zuosicheng/.g/go/src/testing/testing.go:1576 +0x1ca fp=0xc000115888 sp=0xc000115770 pc=0x46e0ca
testing.runTests(0xc0000080c0, {0x721ec0, 0x1, 0x1}, {0xc12d405e15b8c2b0, 0x8bb31bb7ad, 0x72eba0})
        C:/Users/zuosicheng/.g/go/src/testing/testing.go:2034 +0x47d fp=0xc0001159b0 sp=0xc000115888 pc=0x4732dd
testing.(*M).Run(0xc000074140)
        C:/Users/zuosicheng/.g/go/src/testing/testing.go:1906 +0xb8e fp=0xc000115ef0 sp=0xc0001159b0 pc=0x470e6e
main.main()
        _testmain.go:78 +0xd8 fp=0xc000115f80 sp=0xc000115ef0 pc=0x54e3d8
runtime.main()
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:250 +0x1be fp=0xc000115fe0 sp=0xc000115f80 pc=0x2c377e
runtime.goexit()
        C:/Users/zuosicheng/.g/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc000115fe8 sp=0xc000115fe0 pc=0x2f5b01

goroutine 2 [force gc (idle)]:
runtime.gopark(0x5c2298, 0x72e540, 0x11, 0x14, 0x1)
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:381 +0xfd fp=0xc00004df88 sp=0xc00004df58 pc=0x2c3bfd
runtime.goparkunlock(0x0?, 0x0?, 0x0?, 0x0?)
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:387 +0x2a fp=0xc00004dfb8 sp=0xc00004df88 pc=0x2c3c8a
runtime.forcegchelper()
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:305 +0xb0 fp=0xc00004dfe0 sp=0xc00004dfb8 pc=0x2c39d0
runtime.goexit()
        C:/Users/zuosicheng/.g/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc00004dfe8 sp=0xc00004dfe0 pc=0x2f5b01
created by runtime.init.6
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:293 +0x25

goroutine 3 [GC sweep wait]:
runtime.gopark(0x5c2298, 0x72e9e0, 0xc, 0x14, 0x1)
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:381 +0xfd fp=0xc00004ff58 sp=0xc00004ff28 pc=0x2c3bfd
runtime.goparkunlock(0x0?, 0x0?, 0x0?, 0x0?)
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:387 +0x2a fp=0xc00004ff88 sp=0xc00004ff58 pc=0x2c3c8a
runtime.bgsweep(0x0?)
        C:/Users/zuosicheng/.g/go/src/runtime/mgcsweep.go:278 +0x98 fp=0xc00004ffc8 sp=0xc00004ff88 pc=0x2a8f78
runtime.gcenable.func1()
        C:/Users/zuosicheng/.g/go/src/runtime/mgc.go:178 +0x26 fp=0xc00004ffe0 sp=0xc00004ffc8 pc=0x29d386
runtime.goexit()
        C:/Users/zuosicheng/.g/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc00004ffe8 sp=0xc00004ffe0 pc=0x2f5b01
created by runtime.gcenable
        C:/Users/zuosicheng/.g/go/src/runtime/mgc.go:178 +0x6b

goroutine 4 [GC scavenge wait]:
runtime.gopark(0x5c2298, 0x72eca0, 0xd, 0x14, 0x2)
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:381 +0xfd fp=0xc00005ff48 sp=0xc00005ff18 pc=0x2c3bfd
runtime.goparkunlock(0x5d7128?, 0x1?, 0x0?, 0x0?)
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:387 +0x2a fp=0xc00005ff78 sp=0xc00005ff48 pc=0x2c3c8a
runtime.(*scavengerState).park(0x72eca0)
        C:/Users/zuosicheng/.g/go/src/runtime/mgcscavenge.go:400 +0x4b fp=0xc00005ffa0 sp=0xc00005ff78 pc=0x2a6a2b
runtime.bgscavenge(0x0?)
        C:/Users/zuosicheng/.g/go/src/runtime/mgcscavenge.go:628 +0x45 fp=0xc00005ffc8 sp=0xc00005ffa0 pc=0x2a7005
runtime.gcenable.func2()
        C:/Users/zuosicheng/.g/go/src/runtime/mgc.go:179 +0x26 fp=0xc00005ffe0 sp=0xc00005ffc8 pc=0x29d326
runtime.goexit()
        C:/Users/zuosicheng/.g/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc00005ffe8 sp=0xc00005ffe0 pc=0x2f5b01
created by runtime.gcenable
        C:/Users/zuosicheng/.g/go/src/runtime/mgc.go:179 +0xaa

goroutine 5 [finalizer wait]:
runtime.gopark(0x5c20f0, 0x783c30, 0x10, 0x14, 0x1)
        C:/Users/zuosicheng/.g/go/src/runtime/proc.go:381 +0xfd fp=0xc000051e28 sp=0xc000051df8 pc=0x2c3bfd
runtime.runfinq()
        C:/Users/zuosicheng/.g/go/src/runtime/mfinal.go:193 +0x107 fp=0xc000051fe0 sp=0xc000051e28 pc=0x29c3e7
runtime.goexit()
        C:/Users/zuosicheng/.g/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc000051fe8 sp=0xc000051fe0 pc=0x2f5b01
created by runtime.createfing
        C:/Users/zuosicheng/.g/go/src/runtime/mfinal.go:163 +0x50

goroutine 6 [runnable, locked to thread]:
runtime.cgocall(0x2f74a0, 0xc000054ec0)
        C:/Users/zuosicheng/.g/go/src/runtime/cgocall.go:157 +0x4a fp=0xc000148588 sp=0xc000148550 pc=0x2856ca
syscall.SyscallN(0x7ffc695dab30, {0xc0000163e0?, 0x4, 0x0?})
        C:/Users/zuosicheng/.g/go/src/runtime/syscall_windows.go:557 +0x12e fp=0xc000148610 sp=0xc000148588 pc=0x2f26ce
syscall.(*Proc).Call(0xc000058560, {0xc0000163e0, 0x4, 0x4})
        C:/Users/zuosicheng/.g/go/src/syscall/dll_windows.go:190 +0x8d fp=0xc0001486a0 sp=0xc000148610 pc=0x366ecd
syscall.(*LazyProc).Call(0xc00007a8d0, {0xc0000163e0, 0x4, 0x4})
        C:/Users/zuosicheng/.g/go/src/syscall/dll_windows.go:310 +0xa5 fp=0xc000148738 sp=0xc0001486a0 pc=0x367985
github.com/bytedance/mockey/internal/monkey/mem/prot.virtualProtect(0x54d000, 0x1000, 0x40, 0xc00001c5b0)
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/bytedance/mockey@v1.2.4/internal/monkey/mem/prot/protect_windows.go:46 +0xe5 fp=0xc0001487e0 sp=0xc000148738 pc=0x537565
github.com/bytedance/mockey/internal/monkey/mem/prot.mProtectPage(0x54d000, 0x40)
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/bytedance/mockey@v1.2.4/internal/monkey/mem/prot/protect_windows.go:42 +0xa5 fp=0xc000148868 sp=0xc0001487e0 pc=0x537425
github.com/bytedance/mockey/internal/monkey/mem/prot.MProtectRWX(0x54d540)
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/bytedance/mockey@v1.2.4/internal/monkey/mem/prot/protect_windows.go:33 +0x38 fp=0xc0001488b0 sp=0xc000148868 pc=0x537298
github.com/bytedance/mockey/internal/monkey/mem.Write(0x54d540, {0x27c68ff0000, 0xe, 0x1000})
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/bytedance/mockey@v1.2.4/internal/monkey/mem/write_windows.go:25 +0x59 fp=0xc000148958 sp=0xc0001488b0 pc=0x545199
github.com/bytedance/mockey/internal/monkey/mem.WriteWithSTW(0x54d540, {0x27c68ff0000, 0xe, 0x1000})
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/bytedance/mockey@v1.2.4/internal/monkey/mem/write.go:29 +0x94 fp=0xc000148a28 sp=0xc000148958 pc=0x544ff4
github.com/bytedance/mockey/internal/monkey.(*Patch).Unpatch(0xc00007af30)
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/bytedance/mockey@v1.2.4/internal/monkey/patch.go:38 +0x65 fp=0xc000148a98 sp=0xc000148a28 pc=0x545345
github.com/bytedance/mockey.(*Mocker).UnPatch(0xc000028d00)
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/bytedance/mockey@v1.2.4/mock.go:273 +0xe7 fp=0xc000148b48 sp=0xc000148a98 pc=0x549d27 
github.com/bytedance/mockey.(*Mocker).unPatch(0xc000028d00)
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/bytedance/mockey@v1.2.4/mock.go:369 +0x1e fp=0xc000148b60 sp=0xc000148b48 pc=0x54abbe 
github.com/bytedance/mockey.PatchConvey.func1.1()
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/bytedance/mockey@v1.2.4/convey.go:39 +0xc3 fp=0xc000148c10 sp=0xc000148b60 pc=0x54cee3
runtime.deferreturn()
        C:/Users/zuosicheng/.g/go/src/runtime/panic.go:476 +0x33 fp=0xc000148c50 sp=0xc000148c10 pc=0x2bfc33
github.com/bytedance/mockey.PatchConvey.func1({0x783d38, 0x0, 0x0})
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/bytedance/mockey@v1.2.4/convey.go:43 +0x19a fp=0xc000148d40 sp=0xc000148c50 pc=0x54661a
reflect.callReflect(0xc00007ab70, 0xc00006d4e8, 0xc0001493c0, 0xc0001493c8)
        C:/Users/zuosicheng/.g/go/src/reflect/value.go:772 +0x6ab fp=0xc000149370 sp=0xc000148d40 pc=0x347ccb
reflect.callReflect(0xc00007ab70, 0xc00006d4e8, 0xc00006d3c0, 0xc00006d3c8)
        <autogenerated>:1 +0x50 fp=0xc0001493a0 sp=0xc000149370 pc=0x3615d0
reflect.makeFuncStub()
        C:/Users/zuosicheng/.g/go/src/reflect/asm_amd64.s:47 +0x7f fp=0xc0001494e8 sp=0xc0001493a0 pc=0x35907f
github.com/smartystreets/goconvey/convey.parseAction.func1({0xc000008138, 0xc00007acf0})
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/smartystreets/goconvey@v1.6.4/convey/discovery.go:80 +0x22 fp=0xc000149500 sp=0xc0001494e8 pc=0x536042
github.com/smartystreets/goconvey/convey.(*context).conveyInner(0xc00002c180, {0x5afea9, 0xb}, 0xc000056830)
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/smartystreets/goconvey@v1.6.4/convey/context.go:261 +0x2a3 fp=0xc0001496e8 sp=0xc000149500 pc=0x5346c3
github.com/smartystreets/goconvey/convey.rootConvey.func1()
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/smartystreets/goconvey@v1.6.4/convey/context.go:110 +0x1b4 fp=0xc0001497f0 sp=0xc0001496e8 pc=0x533174
github.com/jtolds/gls.(*ContextManager).SetValues.func1(0x0)
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/jtolds/gls@v4.20.0+incompatible/context.go:97 +0x5bc fp=0xc000149a10 sp=0xc0001497f0 pc=0x52939c
github.com/jtolds/gls.EnsureGoroutineId.func1()
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/jtolds/gls@v4.20.0+incompatible/gid.go:24 +0x2e fp=0xc000149a38 sp=0xc000149a10 pc=0x529b4e
github.com/jtolds/gls._m(0x0, 0xc000008168)
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/jtolds/gls@v4.20.0+incompatible/stack_tags.go:108 +0x2f fp=0xc000149a58 sp=0xc000149a38 pc=0x52a8af
github.com/jtolds/gls.github_com_jtolds_gls_markS(0x0, 0xc000008168)
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/jtolds/gls@v4.20.0+incompatible/stack_tags.go:56 +0x25 fp=0xc000149a78 sp=0xc000149a58 pc=0x52a245
github.com/jtolds/gls.addStackTag(0x0, 0xc000008168)
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/jtolds/gls@v4.20.0+incompatible/stack_tags.go:49 +0x2c fp=0xc000149a98 sp=0xc000149a78 pc=0x52a1ec
github.com/jtolds/gls.EnsureGoroutineId(0xc00007ac90)
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/jtolds/gls@v4.20.0+incompatible/gid.go:24 +0x19e fp=0xc000149b60 sp=0xc000149a98 pc=0x529ade
github.com/jtolds/gls.(*ContextManager).SetValues(0xc0000565e0, 0xc00007ac30, 0xc0000584c0)
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/jtolds/gls@v4.20.0+incompatible/context.go:63 +0x1fe fp=0xc000149ba8 sp=0xc000149b60 pc=0x528d9e
github.com/smartystreets/goconvey/convey.rootConvey({0xc00006de58, 0x3, 0x3})
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/smartystreets/goconvey@v1.6.4/convey/context.go:105 +0x36d fp=0xc000149c70 sp=0xc000149ba8 pc=0x532f6d
github.com/smartystreets/goconvey/convey.Convey({0xc00006de58, 0x3, 0x3})
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/smartystreets/goconvey@v1.6.4/convey/doc.go:75 +0x5e fp=0xc000149ca8 sp=0xc000149c70 pc=0x53629e
github.com/bytedance/mockey.PatchConvey({0xc00006de58, 0x3, 0x3})
        C:/Users/zuosicheng/.g/gopath/pkg/mod/github.com/bytedance/mockey@v1.2.4/convey.go:48 +0x251 fp=0xc000149d70 sp=0xc000149ca8 pc=0x546431
main/test4.TestMockXXX(0xc00004b520)
        C:/work/demo/golang_demo/test4/main_test.go:23 +0x112 fp=0xc000149e98 sp=0xc000149d70 pc=0x54d6d2
testing.tRunner(0xc00004b520, 0x5c1ef8)
        C:/Users/zuosicheng/.g/go/src/testing/testing.go:1576 +0x1ca fp=0xc000149fb0 sp=0xc000149e98 pc=0x46e0ca
testing.(*T).Run.func1()
        C:/Users/zuosicheng/.g/go/src/testing/testing.go:1629 +0x39 fp=0xc000149fe0 sp=0xc000149fb0 pc=0x46fc59
runtime.goexit()
        C:/Users/zuosicheng/.g/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc000149fe8 sp=0xc000149fe0 pc=0x2f5b01
created by testing.(*T).Run
        C:/Users/zuosicheng/.g/go/src/testing/testing.go:1629 +0x7a6
FAIL    main/test4      600.313s
=== RUN   TestMockXXX

  TestMockXXX ...

3 total assertions

a
b
0
--- PASS: TestMockXXX (5.00s)
PASS
coverage: [no statements]
ok      main/test5      5.358s  coverage: [no statements]
=== RUN   TestMockXXX

  TestMockXXX ...

3 total assertions

a
b
0
--- PASS: TestMockXXX (5.00s)
PASS
coverage: [no statements]
ok      main/test6      5.308s  coverage: [no statements]
=== RUN   TestMockXXX

  TestMockXXX ...

3 total assertions

a
b
0
--- PASS: TestMockXXX (5.00s)
PASS
coverage: [no statements]
ok      main/test7      5.442s  coverage: [no statements]
=== RUN   TestMockXXX
3 total assertions
a
b
0
--- PASS: TestMockXXX (5.00s)
PASS
coverage: [no statements]
ok      main/test8      5.367s  coverage: [no statements]
=== RUN   TestMockXXX

  TestMockXXX ...
Sychorius commented 10 months ago

Describe the bug

When running “go test” on multiple test files in different packages concurrently, deadlock may occur in windows system.

To Reproduce

Steps to reproduce the behavior:

  1. Create a folder “test1” with files: “main_test.go".
import (
  "fmt"
  "testing"
  "time"
  . "github.com/bytedance/mockey"
  . "github.com/smartystreets/goconvey/convey"
)

func Foo(in string) string {
  return in
}

type A struct{}

func (a A) Foo(in string) string { return in }

var Bar = 0

func TestMockXXX(t *testing.T) {
  PatchConvey("TestMockXXX", t, func() {
      Mock(Foo).Return("c").Build()   // mock function
      Mock(A.Foo).Return("c").Build() // mock method
      MockValue(&Bar).To(1)           // mock variable
      time.Sleep(5 * time.Second)
      So(Foo("a"), ShouldEqual, "c")        // assert `Foo` is mocked
      So(new(A).Foo("b"), ShouldEqual, "c") // assert `A.Foo` is mocked
      So(Bar, ShouldEqual, 1)               // assert `Bar` is mocked
  })
  // mock is released automatically outside `PatchConvey`
  fmt.Println(Foo("a"))        // a
  fmt.Println(new(A).Foo("b")) // b
  fmt.Println(Bar)             // 0
}
  1. Copy the test1 folder 15 times.
  2. CD to the parent folder of “test1” and execute the following command: go test -gcflags="all=-l -N" -p 1 -v -cover -covermode count -coverprofile cover.out ./...
  3. The error runtime: checkdead: find g 19 in status 1 occurred.

Mockey version:

github.com/bytedance/mockey v1.2.4

Environment:

set GOVERSION=go1.20.1 set GCCGO=gccgo set GOAMD64=v1

Mockey does not support parallel testing. But it Looks weird. Since you added -p 1 and didn't use t.Parallel(), your packages will not meet the concurrecy problem because your tests ran one by one. Are you sure you ran different package tests concurrently ?

201907 commented 10 months ago

@Sychorius

Mockey does not support parallel testing. But it Looks weird. Since you added -p 1 and didn't use t.Parallel(), your packages will not meet the concurrecy problem because your tests ran one by one. Are you sure you ran different package tests concurrently ?

I'm sorry I misspoke. I want different package test cases to be executed without concurrency so I added the argument -p 1.

runtime: checkdead: find g 19 in status 1

This error sometimes occurs and sometimes does not occur. There are also cases where all tests are successful. And when an error occurs, the test case often stalls for about ten minutes.

Sychorius commented 9 months ago

We have tried on win+go1.20 many times with more cases but it never occurs. Closed for there is no more infomations and currently we can't reproduce it. Reopen If anyone else meet the same issue.