-
Notifications
You must be signed in to change notification settings - Fork 153
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
goleak finds goroutine leak in not enabled test case #83
Comments
Hey, So I've been looking into this a bit, and at its core, this issue is very similar to supporting This is a bit of a non-trivial problem. One idea is to use tracebackancestors, one of the runtime GODEBUG variables, but as pointed out in #70, this doesn't soundly catch all cases because goroutines whose parents are killed won't be able to be traced back to their original test function. Another idea is to keep some sort of internal ignore list for goroutines to filter by that gets augmented at the end of every test. This is the equivalent of calling IgnoreCurrent after every test function and building up a large ignore list, but doing it internally. But this (a) won't work with parallel and (b) will require making some API call at the end of every test function, so that's not very satisfying either. To solve this issue, we'd want some sort of way to attach baggage to created goroutines so that we can make them aware of the test function they originated from, but unfortunately this is not something Go supports. |
same bug happens to me. The goleak lib needs to be removed in the impacted tests to make CI work |
1 similar comment
same bug happens to me. The goleak lib needs to be removed in the impacted tests to make CI work |
Just echoing what @JacobOaks said: this isn't easily solvable. There was some prior discussion here: #16 (comment) Basically, there's no easy way to associate goroutines to the test that spawn it when used with t.Parallel. @JacobOaks medium term, we should probably document this in VerifyNone docs: if the test uses t.Parallel, then there's only so much goleak can do, and you should probably use VerifyTestMain in that case. Long-term, if the runtime gives us the appropriate information to correlate the goroutine to the test that spawned it, we should definitely try to use that. |
It's a known issue that goleak is incompatible with tests being run in parallel. * uber-go#16 * uber-go#83 Unfortunately, there is no real solution to this issue. * uber-go#16 (comment) * uber-go#83 (comment) * uber-go#83 (comment) This PR at least documents the incompatibility and suggests using `VerifyTestMain` instead.
It's a known issue that goleak is incompatible with tests being run in parallel. * #16 * #83 Unfortunately, there is no real solution to this issue. * #16 (comment) * #83 (comment) * #83 (comment) This PR at least documents the incompatibility and suggests using `VerifyTestMain` instead.
If you have a module with a leak in func leak():
and tests checking for leaks by running
defer goleak.VerifyNone(t)
, that don't run leak(), it will show a leak in TestC, even if the leak is in TestB withoutdefer goleak.VerifyNone(t)
:It depends on order of execution of tests.
Here a test run:
The text was updated successfully, but these errors were encountered: