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

IgnoreAnyFunc not checked for "created by" #135

Open
pohly opened this issue Nov 28, 2024 · 2 comments
Open

IgnoreAnyFunc not checked for "created by" #135

pohly opened this issue Nov 28, 2024 · 2 comments

Comments

@pohly
Copy link

pohly commented Nov 28, 2024

I have one test which leaks a goroutine. The only part of the stack backtraces which refers to that test is in the "created by k8s.io/client-go/tools/cache.TestReflectorListAndWatch" (full output in the details).

When I try to suppress the test with goleak.IgnoreAnyFunction("k8s.io/client-go/tools/cache.TestReflectorListAndWatch"), the suppression is ignored.

Here's my TestMain:

func TestMain(m *testing.M) {
	options := []goleak.Option{
		// These tests run goroutines which get stuck in Pop.
		// This cannot be fixed without modifying the API.
		goleak.IgnoreAnyFunction("k8s.io/client-go/tools/cache.TestFIFO_addReplace.func1"),
		goleak.IgnoreAnyFunction("k8s.io/client-go/tools/cache.TestFIFO_addUpdate.func1"),
		goleak.IgnoreAnyFunction("k8s.io/client-go/tools/cache.TestDeltaFIFO_addReplace.func1"),
		goleak.IgnoreAnyFunction("k8s.io/client-go/tools/cache.TestDeltaFIFO_addUpdate.func1"),

		// TODO: fix the following tests by adding WithContext APIs and cancellation.
		goleak.IgnoreAnyFunction("k8s.io/client-go/tools/cache.TestReflectorListAndWatch"),
		goleak.IgnoreAnyFunction("k8s.io/client-go/tools/cache.TestTransformingInformerRace.func3"),
	}
	goleak.VerifyTestMain(m, options...)
}

I suppose "where the specified function is present anywhere in the stack" refers to the stack of the running goroutine, not the one which created it. I would find it useful to extend that or add a IgnoreAnyCreatorFunc with that semantic.

goleak: Errors on successful test run: found unexpected goroutines:
[Goroutine 91 in state sync.Mutex.Lock, with sync.runtime_SemacquireMutex on top of the stack:
sync.runtime_SemacquireMutex(0xc00005ea08?, 0x80?, 0x40bae8?)
	/nvme/gopath/go-1.23.0/src/runtime/sema.go:95 +0x25
sync.(*Mutex).lockSlow(0xc000418e70)
	/nvme/gopath/go-1.23.0/src/sync/mutex.go:173 +0x15d
sync.(*Mutex).Lock(...)
	/nvme/gopath/go-1.23.0/src/sync/mutex.go:92
sync.(*RWMutex).Lock(0xc0003907a8?)
	/nvme/gopath/go-1.23.0/src/sync/rwmutex.go:148 +0x31
k8s.io/client-go/tools/cache.(*DeltaFIFO).Close(0xc000418e70)
	/nvme/gopath/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/delta_fifo.go:274 +0x26
k8s.io/client-go/tools/cache.(*controller).Run.func1()
	/nvme/gopath/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/controller.go:139 +0x37
created by k8s.io/client-go/tools/cache.(*controller).Run in goroutine 90
	/nvme/gopath/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/controller.go:137 +0xab
 Goroutine 107 in state select, with k8s.io/client-go/tools/cache.handleAnyWatch on top of the stack:
k8s.io/client-go/tools/cache.handleAnyWatch({0xe2c267?, 0x1?, 0x156ca80?}, {0xf8d470, 0xc0003fc378}, {0xf994e0, 0xc00019e090}, {0xfa2560, 0xe03c40}, 0x0, ...)
	/nvme/gopath/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/reflector.go:802 +0x230
k8s.io/client-go/tools/cache.handleWatch({0x1?, 0x0?, 0x156ca80?}, {0xf8d470?, 0xc0003fc378?}, {0xf994e0?, 0xc00019e090?}, {0xfa2560?, 0xe03c40?}, 0x0, ...)
	/nvme/gopath/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/reflector.go:768 +0xdd
k8s.io/client-go/tools/cache.(*Reflector).watch(0xc0006b3d10, {0x0?, 0x0?}, 0xc0000eca10, 0xc000a00380)
	/nvme/gopath/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/reflector.go:466 +0x556
k8s.io/client-go/tools/cache.(*Reflector).watchWithResync(0xc0006b3d10, {0x0, 0x0}, 0xc0000eca10)
	/nvme/gopath/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/reflector.go:414 +0x12c
k8s.io/client-go/tools/cache.(*Reflector).ListAndWatch(0xc0006b3d10, 0xc0000eca10)
	/nvme/gopath/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/reflector.go:377 +0x3c5
created by k8s.io/client-go/tools/cache.TestReflectorListAndWatch in goroutine 106
	/nvme/gopath/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/reflector_test.go:445 +0x2c9
 Goroutine 94 in state sync.Mutex.Lock, with sync.runtime_SemacquireMutex on top of the stack:
sync.runtime_SemacquireMutex(0x41c4d6?, 0xe0?, 0xc00082ce90?)
	/nvme/gopath/go-1.23.0/src/runtime/sema.go:95 +0x25
sync.(*Mutex).lockSlow(0xc000418e70)
	/nvme/gopath/go-1.23.0/src/sync/mutex.go:173 +0x15d
sync.(*Mutex).Lock(...)
	/nvme/gopath/go-1.23.0/src/sync/mutex.go:92
sync.(*RWMutex).Lock(0xc0000ed1f0?)
	/nvme/gopath/go-1.23.0/src/sync/rwmutex.go:148 +0x31
k8s.io/client-go/tools/cache.(*DeltaFIFO).Resync(0xc000418e70)
	/nvme/gopath/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/delta_fifo.go:721 +0x30
k8s.io/client-go/tools/cache.(*Reflector).startResync(0xc0001a1d10, 0xc0000ed1f0, 0xc0000ed2d0, 0xc000a00690)
	/nvme/gopath/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/reflector.go:398 +0x225
created by k8s.io/client-go/tools/cache.(*Reflector).watchWithResync in goroutine 92
	/nvme/gopath/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/reflector.go:413 +0x105
 Goroutine 109 in state select, with k8s.io/client-go/tools/cache.(*Reflector).startResync on top of the stack:
k8s.io/client-go/tools/cache.(*Reflector).startResync(0xc0006b3d10, 0xc0000eca10, 0xc0000eccb0, 0xc000a00380)
	/nvme/gopath/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/reflector.go:389 +0x106
created by k8s.io/client-go/tools/cache.(*Reflector).watchWithResync in goroutine 107
	/nvme/gopath/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/reflector.go:413 +0x105
]
FAIL	k8s.io/client-go/tools/cache	36.808s
@abhinav
Copy link
Collaborator

abhinav commented Nov 28, 2024

This is a reasonable request. When IgnoreAnyFunction was originally implemented (#113), we discussed whether creator is part of the stack for IgnoreAnyFunction, and decided no. We figured we could add an IgnoreCreatedBy in the future if needed.

Would you be willing to take a stab at a PR for IgnoreCreatedBy?

@pohly
Copy link
Author

pohly commented Nov 28, 2024

Sorry, not anytime soon, I have too much on my plate already. It's also not particularly high priority because that test will soon not leak goroutines anymore, I just wanted to report this in case that your weren't aware.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants