MCPcopy
hub / github.com/uber-go/goleak

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

repository ↗ · DeepWiki ↗ · release v1.3.0 ↗
95 symbols 357 edges 16 files 30 documented · 32%
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

Option (Interface)
Option lets users specify custom verifications. [1 implementers]
options.go
TestingT (Interface)
TestingT is the minimal subset of testing.TB that we use. [1 implementers]
leaks.go
TestingM (Interface)
TestingM is the minimal subset of testing.M that we use.
testmain.go

Core symbols most depended-on inside this repo

ID
called by 19
internal/stack/stacks.go
Run
called by 15
testmain.go
Find
called by 14
leaks.go
Full
called by 12
internal/stack/stacks.go
VerifyNone
called by 11
leaks.go
HasFunction
called by 10
internal/stack/stacks.go
All
called by 10
internal/stack/stacks.go
buildOpts
called by 8
options.go

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

github.com/davecgh/go-spewv1.1.1 · 1×
github.com/kr/prettyv0.1.0 · 1×
github.com/pmezard/go-difflibv1.0.0 · 1×
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