Skip to content

Commit

Permalink
Fix Goroutine leaks in several packages (jaegertracing#5066)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?
- fix gorourine leak in some packages 

## Description of the changes
- part of jaegertracing#5006 

## How was this change tested?
- go test

## Checklist
- [x] I have read
https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md
- [x] I have signed all commits
- [x] I have run lint and test steps successfully
  - for `jaeger`: `make lint test`

---------

Signed-off-by: Harshvir Potpose <hpotpose62@gmail.com>
  • Loading branch information
akagami-harsh authored Dec 30, 2023
1 parent 003111b commit 5c6348e
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cmd/ingester/app/consumer/package_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2023 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 consumer

import (
"testing"

"go.uber.org/goleak"
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}
1 change: 1 addition & 0 deletions cmd/ingester/app/consumer/processor_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func Test_new(t *testing.T) {
}

processor := pf.new(topic, partition, offset)
defer processor.Close()
msg := &kmocks.Message{}
msg.On("Offset").Return(offset + 1)
processor.Process(msg)
Expand Down
7 changes: 7 additions & 0 deletions cmd/internal/env/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (
"testing"

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

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

func TestCommand(t *testing.T) {
Expand All @@ -30,3 +33,7 @@ func TestCommand(t *testing.T) {
assert.True(t, strings.Contains(buf.String(), "METRICS_BACKEND"))
assert.True(t, strings.Contains(buf.String(), "SPAN_STORAGE"))
}

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m, testutils.IgnoreGlogFlushDaemonLeak())
}
27 changes: 27 additions & 0 deletions pkg/testutils/leakcheck.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2023 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 (
"go.uber.org/goleak"
)

// IgnoreGlogFlushDaemonLeak returns a goleak.Option that ignores the flushDaemon function
// from the glog package that can cause false positives in leak detection.
// This is necessary because glog starts a goroutine in the background that may not
// be stopped when the test finishes, leading to a detected but expected leak.
func IgnoreGlogFlushDaemonLeak() goleak.Option {
return goleak.IgnoreTopFunction("github.com/golang/glog.(*fileSink).flushDaemon")
}
26 changes: 26 additions & 0 deletions pkg/testutils/leakcheck_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2023 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"
)

func TestIgnoreGlogFlushDaemonLeak(t *testing.T) {
opt := IgnoreGlogFlushDaemonLeak()
if opt == nil {
t.Errorf("IgnoreGlogFlushDaemonLeak() returned nil, want non-nil goleak.Option")
}
}
27 changes: 27 additions & 0 deletions plugin/storage/badger/dependencystore/package_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2023 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 dependencystore

import (
"testing"

"go.uber.org/goleak"

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

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m, testutils.IgnoreGlogFlushDaemonLeak())
}
27 changes: 27 additions & 0 deletions plugin/storage/badger/package_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2023 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 badger

import (
"testing"

"go.uber.org/goleak"

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

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m, testutils.IgnoreGlogFlushDaemonLeak())
}
6 changes: 6 additions & 0 deletions plugin/storage/badger/samplingstore/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import (
"github.com/dgraph-io/badger/v3"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"

samplemodel "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/model"
"github.com/jaegertracing/jaeger/pkg/testutils"
)

func newTestSamplingStore(db *badger.DB) *SamplingStore {
Expand Down Expand Up @@ -139,3 +141,7 @@ func runWithBadger(t *testing.T, test func(t *testing.T, store *SamplingStore))
ss := newTestSamplingStore(store)
test(t, ss)
}

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m, testutils.IgnoreGlogFlushDaemonLeak())
}
27 changes: 27 additions & 0 deletions plugin/storage/badger/spanstore/package_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2023 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 spanstore

import (
"testing"

"go.uber.org/goleak"

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

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m, testutils.IgnoreGlogFlushDaemonLeak())
}
2 changes: 2 additions & 0 deletions plugin/storage/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,9 @@ func TestPublishOpts(t *testing.T) {
require.NoError(t, err)

baseMetrics := metricstest.NewFactory(time.Second)
baseMetrics.Stop()
forkFactory := metricstest.NewFactory(time.Second)
forkFactory.Stop()
metricsFactory := fork.New("internal", forkFactory, baseMetrics)
f.metricsFactory = metricsFactory

Expand Down
27 changes: 27 additions & 0 deletions plugin/storage/package_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2023 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 storage

import (
"testing"

"go.uber.org/goleak"

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

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

0 comments on commit 5c6348e

Please sign in to comment.