0

I'm trying to detect goroutine leaks in my Go tests. However, the existing libraries I've seen all detect global leaks, not leaks of goroutines which are descendents of the test function. I want this functionality for two reasons:

  1. It allows me to detect leaks while still running tests in parallel (e.g. using t.Parallel())
  2. It will ignore leaks which are just the fault of init functions. This happens a lot in our codebase because we have, for example, a logging library imported which creates a long-running goroutine in its init function.

This is now possible with the addition of GODEBUG=tracebackancestors=n (proposal, docs).

In lieue of an existing leak detection library which does what I want, I'd like to build my own, but I don't want to write my own logic for parsing the output of runtime.Stack because it's just an unstructured string. I'd like a library which can give me the actual parsed, structured, stack/goroutine information. Is there an existing library which does this? Alternatively, is there a goroutine leak detection library which does what I want?

1 Answer 1

1

I made a pull request for this for gostackparse at https://github.com/DataDog/gostackparse/pull/3. If this gets accepted, let's just update this answer to say that it's supported by the package.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.