Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use goleak to capture goroutine leak #2606

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/flags/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"go.uber.org/goleak"
)

func TestMain(m *testing.M) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manually adding these functions is not a scalable approach, next time someone will surely forget to add one.

I would prefer to have a CI check, similar to make nocover, that will fail if some packages don't have this function (assuming we want to go with checking these leaks).

goleak.VerifyTestMain(m)
}

func TestParseJaegerTags(t *testing.T) {

jaegerTags := fmt.Sprintf("%s,%s,%s,%s,%s,%s",
Expand Down
5 changes: 5 additions & 0 deletions cmd/opentelemetry/app/defaultconfig/default_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ import (
"github.com/jaegertracing/jaeger/cmd/opentelemetry/app/exporter/memoryexporter"
"github.com/jaegertracing/jaeger/cmd/opentelemetry/app/receiver/kafkareceiver"
jConfig "github.com/jaegertracing/jaeger/pkg/config"
"github.com/jaegertracing/jaeger/pkg/testutils"
)

func TestMain(m *testing.M) {
testutils.TolerantVerifyLeakMain(m)
}

func TestService(t *testing.T) {
tests := []struct {
service configmodels.Service
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2020 The Jaeger Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package badgerexporter

import (
"testing"

"github.com/jaegertracing/jaeger/pkg/testutils"
)

func TestMain(m *testing.M) {
testutils.TolerantVerifyLeakMain(m)
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ import (

"github.com/jaegertracing/jaeger/cmd/opentelemetry/app/receiver/jaegerreceiver"
jConfig "github.com/jaegertracing/jaeger/pkg/config"
"github.com/jaegertracing/jaeger/pkg/testutils"
)

func TestMain(m *testing.M) {
testutils.TolerantVerifyLeakMain(m)
}

func TestDefaultValues(t *testing.T) {
v, c := jConfig.Viperize(jaegerreceiver.AddFlags)
err := c.ParseFlags([]string{})
Expand Down
25 changes: 25 additions & 0 deletions cmd/opentelemetry/app/internal/esclient/esclient_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2020 The Jaeger Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package esclient

import (
"testing"

"go.uber.org/goleak"
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}
5 changes: 5 additions & 0 deletions cmd/opentelemetry/app/internal/esutil/index_name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ import (
"time"

"github.com/stretchr/testify/assert"
"go.uber.org/goleak"
)

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

func TestIndexNames(t *testing.T) {
tests := []struct {
name string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/cmd/opentelemetry/app/internal/esclient"
Expand All @@ -35,6 +36,10 @@ import (

const defaultMaxDocCount = 10_000

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

func TestCreateTemplates(t *testing.T) {
client := &mockClient{}
store := NewDependencyStore(client, zap.NewNop(), "foo", defaultMaxDocCount)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2020 The Jaeger Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package esspanreader

import (
"testing"

"go.uber.org/goleak"
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ import (

"github.com/jaegertracing/jaeger/cmd/flags"
jConfig "github.com/jaegertracing/jaeger/pkg/config"
"github.com/jaegertracing/jaeger/pkg/testutils"
)

func TestMain(m *testing.M) {
testutils.TolerantVerifyLeakMain(m)
}

func TestDefaultValues(t *testing.T) {
v, c := jConfig.Viperize(AddFlags)
err := c.ParseFlags([]string{})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ import (

collectorApp "github.com/jaegertracing/jaeger/cmd/collector/app"
jConfig "github.com/jaegertracing/jaeger/pkg/config"
"github.com/jaegertracing/jaeger/pkg/testutils"
"github.com/jaegertracing/jaeger/plugin/sampling/strategystore/static"
)

func TestMain(m *testing.M) {
testutils.TolerantVerifyLeakMain(m)
}

func TestDefaultValues(t *testing.T) {
v, c := jConfig.Viperize(AddFlags)
err := c.ParseFlags([]string{})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ import (

"github.com/jaegertracing/jaeger/cmd/flags"
jConfig "github.com/jaegertracing/jaeger/pkg/config"
"github.com/jaegertracing/jaeger/pkg/testutils"
"github.com/jaegertracing/jaeger/plugin/storage/kafka"
)

func TestMain(m *testing.M) {
testutils.TolerantVerifyLeakMain(m)
}

func TestDefaultConfig(t *testing.T) {
v, c := jConfig.Viperize(AddFlags)
err := c.ParseFlags([]string{""})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ import (
"go.opentelemetry.io/collector/receiver/zipkinreceiver"

jConfig "github.com/jaegertracing/jaeger/pkg/config"
"github.com/jaegertracing/jaeger/pkg/testutils"
)

func TestMain(m *testing.M) {
testutils.TolerantVerifyLeakMain(m)
}

func TestDefaultValues(t *testing.T) {
v, c := jConfig.Viperize(AddFlags)
err := c.ParseFlags([]string{})
Expand Down
1 change: 1 addition & 0 deletions cmd/opentelemetry/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ require (
github.com/uber/jaeger-lib v2.4.0+incompatible
go.opencensus.io v0.22.4
go.opentelemetry.io/collector v0.12.0
go.uber.org/goleak v1.1.10
go.uber.org/zap v1.16.0
)
25 changes: 25 additions & 0 deletions crossdock/services/services_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2020 The Jaeger Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package services

import (
"testing"

"go.uber.org/goleak"
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ require (
go.mongodb.org/mongo-driver v1.3.2 // indirect
go.uber.org/atomic v1.6.0
go.uber.org/automaxprocs v1.3.0
go.uber.org/goleak v1.1.10
go.uber.org/zap v1.16.0
golang.org/x/lint v0.0.0-20200302205851-738671d3881b
golang.org/x/net v0.0.0-20200625001655-4c5254603344
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,8 @@ go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk=
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/automaxprocs v1.3.0 h1:II28aZoGdaglS5vVNnspf28lnZpXScxtIozx1lAjdb0=
go.uber.org/automaxprocs v1.3.0/go.mod h1:9CWT6lKIep8U41DDaPiH6eFscnTyjfTANNQNx6LrIcA=
go.uber.org/goleak v1.1.10 h1:z+mqJhf6ss6BSfSM671tgKyZBFPTTJM+HLxnhPC3wu0=
go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
go.uber.org/multierr v1.5.0 h1:KCa4XfM8CWFCpxXRGok+Q0SS/0XBhMDbHHGABQLvD2A=
Expand Down Expand Up @@ -729,6 +731,7 @@ golang.org/x/tools v0.0.0-20190617190820-da514acc4774/go.mod h1:/rFqwRUd4F7ZHNgw
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
Expand Down
46 changes: 46 additions & 0 deletions pkg/testutils/testutils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) 2020 The Jaeger Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package testutils

import (
"testing"

"go.uber.org/goleak"
)

// TolerantVerifyLeakMain verifies go leaks but excludes the go routines that are
// launched as side effects of some of our dependencies.
func TolerantVerifyLeakMain(m *testing.M) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unfortunate. Seems to indicate that the tests are not closing the resources properly, or the dependencies are not exposing proper clean-up functions.

goleak.VerifyTestMain(m,
// https://github.com/census-instrumentation/opencensus-go/blob/d7677d6af5953e0506ac4c08f349c62b917a443a/stats/view/worker.go#L34
goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where do we even use opencensus?

// https://github.com/kubernetes/klog/blob/c85d02d1c76a9ebafa81eb6d35c980734f2c4727/klog.go#L417
goleak.IgnoreTopFunction("k8s.io/klog/v2.(*loggingT).flushDaemon"),
goleak.IgnoreTopFunction("k8s.io/klog.(*loggingT).flushDaemon"),
// https://github.com/dgraph-io/badger/blob/v1.5.3/y/watermark.go#L54
goleak.IgnoreTopFunction("github.com/dgraph-io/badger/y.(*WaterMark).process"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if feels like badger should really have proper clean-ups, maybe we're not invoking them?

// https://github.com/dgraph-io/badger/blob/v1.5.3/db.go#L264
goleak.IgnoreTopFunction("github.com/dgraph-io/badger.(*DB).updateSize"),
// https://github.com/dgraph-io/badger/blob/v1.5.3/levels.go#L177
goleak.IgnoreTopFunction("time.Sleep"),
// https://github.com/dgraph-io/badger/blob/v1.5.3/levels.go#L177
goleak.IgnoreTopFunction("github.com/dgraph-io/badger.(*levelsController).runWorker"),
goleak.IgnoreTopFunction("github.com/dgraph-io/badger.(*DB).flushMemtable"),
goleak.IgnoreTopFunction("github.com/dgraph-io/badger.(*DB).doWrites"),
goleak.IgnoreTopFunction("github.com/dgraph-io/badger.(*valueLog).waitOnGC"),
goleak.IgnoreTopFunction("github.com/jaegertracing/jaeger/plugin/storage/badger.(*Factory).maintenance"),
goleak.IgnoreTopFunction("github.com/jaegertracing/jaeger/plugin/storage/badger.(*Factory).metricsCopier"),
)
}