bazel-contrib / rules_go

Go rules for Bazel
Apache License 2.0
1.38k stars 656 forks source link

go_test: goroutine leak in RegisterTimeoutHandler #4003

Closed Roytangrb closed 2 months ago

Roytangrb commented 2 months ago

What version of rules_go are you using?

v0.49.0

What version of gazelle are you using?

v0.37.0

What version of Bazel are you using?

5.4.0

Does this issue reproduce with the latest releases of all the above?

Yes

What operating system and processor architecture are you using?

Darwin arm64

Any other potentially useful information about your toolchain?

What did you do?

Go tests that do not send SIGTERM or do not timeout will fail goleak check because this go func waiting to receive SIGTERM

https://github.com/bazelbuild/rules_go/blob/86a7f025d2fc052ab6154603b481cb7e4419598f/go/tools/bzltestutil/timeout.go#L40-L44

What did you expect to see?

User code go test should pass without the workaround of goleak.VerifyTestMain(m, goleak.IgnoreTopFunction("github.com/bazelbuild/rules_go/go/tools/bzltestutil.RegisterTimeoutHandler.func1"))

What did you see instead?

[Goroutine 51 in state chan receive, with github.com/bazelbuild/rules_go/go/tools/bzltestutil.RegisterTimeoutHandler.func1 on top of the stack:
goroutine 51 [chan receive]:
github.com/bazelbuild/rules_go/go/tools/bzltestutil.RegisterTimeoutHandler.func1()
        external/io_bazel_rules_go/go/tools/bzltestutil/timeout.go:43 +0x24
created by github.com/bazelbuild/rules_go/go/tools/bzltestutil.RegisterTimeoutHandler in goroutine 1
        external/io_bazel_rules_go/go/tools/bzltestutil/timeout.go:42 +0x98
]