MCPcopy Index your code
hub / github.com/uber-go/goleak

github.com/uber-go/goleak @v1.3.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.3.0 ↗ · + Follow
95 symbols 357 edges 16 files 30 documented · 32% 114 cross-repo links updated 37d agov1.3.0 · 2023-10-24★ 5,23212 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

goleak GoDoc Build Status Coverage Status

Goroutine leak detector to help avoid Goroutine leaks.

Installation

You can use go get to get the latest version:

go get -u go.uber.org/goleak

goleak also supports semver releases.

Note that go-leak only supports the two most recent minor versions of Go.

Quick Start

To verify that there are no unexpected goroutines running at the end of a test:

func TestA(t *testing.T) {
    defer goleak.VerifyNone(t)

    // test logic here.
}

Instead of checking for leaks at the end of every test, goleak can also be run at the end of every test package by creating a TestMain function for your package:

func TestMain(m *testing.M) {
    goleak.VerifyTestMain(m)
}

Determine Source of Package Leaks

When verifying leaks using TestMain, the leak test is only run once after all tests have been run. This is typically enough to ensure there's no goroutines leaked from tests, but when there are leaks, it's hard to determine which test is causing them.

You can use the following bash script to determine the source of the failing test:

# Create a test binary which will be used to run each test individually
$ go test -c -o tests

# Run each test individually, printing "." for successful tests, or the test name
# for failing tests.
$ for test in $(go test -list . | grep -E "^(Test|Example)"); do ./tests -test.run "^$test\$" &>/dev/null && echo -n "." || echo -e "\n$test failed"; done

This will only print names of failing tests which can be investigated individually. E.g.,

.....
TestLeakyTest failed
.......

Stability

goleak is v1 and follows SemVer strictly.

No breaking changes will be made to exported APIs before 2.0.

Extension points exported contracts — how you extend this code

Core symbols most depended-on inside this repo

Shape

Function 55
Method 26
Struct 7
Interface 4
TypeAlias 2
FuncType 1

Languages

Go100%

Modules by API surface

options.go18 symbols
internal/stack/stacks.go17 symbols
internal/stack/stacks_test.go16 symbols
leaks_test.go8 symbols
utils_test.go7 symbols
leaks.go7 symbols
testmain_test.go6 symbols
internal/stack/scan.go4 symbols
testmain.go3 symbols
options_test.go3 symbols
internal/stack/testdata/http.go3 symbols
tracestack_new.go1 symbols

Dependencies from manifests, versioned

gopkg.in/check.v1v1.0.0-2018062817310 · 1×
gopkg.in/yaml.v3v3.0.1 · 1×

For agents

$ claude mcp add goleak \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page