Skip to content

Unit tests leak goroutines #3962

@stevesg

Description

@stevesg

Spent the morning debugging what I thought was a goroutine leak, but turned out to be just a huge number of goroutines being created in a short period of time. However, it seems a lot of the unit tests do leak goroutines. Most of these might just be issues with tests not cleaning up properly, but it makes testing/debugging real leaks quite difficult. Or in my case, the leaks were a red herring - the issue was something else.

Given we already have goleak vendored in presumably from Prometheus (they use it), it would be nice to start using it.

We leak ~2000 goroutines per full run of the unit tests. Summary below, full data here: unit-test-leaks.txt

top 5 leakers by package

928	pkg/distributor
224	pkg/ingester
147	pkg/chunk/storage
122	pkg/compactor
81	pkg/querier

top 5 leakers by func

1153	github.com/cortexproject/cortex/pkg/ring/kv/consul.(*mockKV).loop
109	internal/poll.runtime_pollWait
68	runtime.goparkunlock
65	github.com/prometheus/prometheus/tsdb/wal.(*WAL).run
62	google.golang.org/grpc.(*addrConn).resetTransport

(Changes used are here - stevesg@b0a95a2 )

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueThese are great first issues. If you are looking for a place to start, start here!help wantedtype/tests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions