Skip to content
Goroutine leak detector
Go Makefile
Branch: master
Clone or download
abhinav README: Mark as stable (#43)
Since we've tagged a 1.0, we can consider this library stable.

I've moved the stability section to the bottom since it's no longer
needed as a deterrent near the top.
Latest commit 8d7a168 Jan 11, 2020
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
internal/stack
.gitignore Migrate to Go modules (#38) Nov 11, 2019
.travis.yml Migrate to Go modules (#38) Nov 11, 2019
CHANGELOG.md Prep changelog for 1.0.0 release (#42) Jan 7, 2020
LICENSE
Makefile Ignore blocked trace stack by default (#40) Jan 7, 2020
README.md README: Mark as stable (#43) Jan 10, 2020
doc.go doc: add doc.go with custom import comment (#15) Mar 21, 2018
glide.yaml
go.mod Migrate to Go modules (#38) Nov 11, 2019
go.sum Migrate to Go modules (#38) Nov 11, 2019
leaks.go Reduce stutter in API for 1.0 release (#27) Nov 12, 2018
leaks_test.go Add latest versions to Travis, support 1.10+ only (#35) Aug 23, 2019
options.go Ignore blocked trace stack by default (#40) Jan 7, 2020
options_test.go Fix flaky tests (#36) Nov 11, 2019
signal_test.go Reduce stutter in API for 1.0 release (#27) Nov 12, 2018
testmain.go Add reference to official Go testing docs (#28) Nov 14, 2018
testmain_test.go Add VerifyTestMain function for easy test integration (#7) Nov 14, 2017
tools.go Migrate to Go modules (#38) Nov 11, 2019
utils_test.go Fix flaky tests (#36) Nov 11, 2019

README.md

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. It is compatible with Go 1.5+.

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 "^Test"); do ./tests -test.run "^$test\$" &>/dev/null && echo -n "." || echo "\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.

You can’t perform that action at this time.