diff --git a/config/configgrpc/configgrpc_test.go b/config/configgrpc/configgrpc_test.go index 1cb29e09a21..c1fa1aa9b02 100644 --- a/config/configgrpc/configgrpc_test.go +++ b/config/configgrpc/configgrpc_test.go @@ -631,6 +631,7 @@ func TestHttpReception(t *testing.T) { } grpcClientConn, errClient := gcs.ToClientConn(context.Background(), componenttest.NewNopHost(), tt.TelemetrySettings()) assert.NoError(t, errClient) + defer func() { assert.NoError(t, grpcClientConn.Close()) }() c := ptraceotlp.NewGRPCClient(grpcClientConn) ctx, cancelFunc := context.WithTimeout(context.Background(), 2*time.Second) resp, errResp := c.Export(ctx, ptraceotlp.NewExportRequest(), grpc.WaitForReady(true)) @@ -679,6 +680,7 @@ func TestReceiveOnUnixDomainSocket(t *testing.T) { } grpcClientConn, errClient := gcs.ToClientConn(context.Background(), componenttest.NewNopHost(), tt.TelemetrySettings()) assert.NoError(t, errClient) + defer func() { assert.NoError(t, grpcClientConn.Close()) }() c := ptraceotlp.NewGRPCClient(grpcClientConn) ctx, cancelFunc := context.WithTimeout(context.Background(), 2*time.Second) resp, errResp := c.Export(ctx, ptraceotlp.NewExportRequest(), grpc.WaitForReady(true)) @@ -887,6 +889,7 @@ func TestClientInfoInterceptors(t *testing.T) { grpcClientConn, errClient := gcs.ToClientConn(context.Background(), componenttest.NewNopHost(), tt.TelemetrySettings()) require.NoError(t, errClient) + defer func() { assert.NoError(t, grpcClientConn.Close()) }() cl := ptraceotlp.NewGRPCClient(grpcClientConn) ctx, cancelFunc := context.WithTimeout(context.Background(), 2*time.Second) diff --git a/config/configgrpc/go.mod b/config/configgrpc/go.mod index 38ca9b368fc..4e87d2a6ea4 100644 --- a/config/configgrpc/go.mod +++ b/config/configgrpc/go.mod @@ -17,6 +17,7 @@ require ( go.opentelemetry.io/collector/pdata v1.0.1 go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.47.0 go.opentelemetry.io/otel v1.22.0 + go.uber.org/goleak v1.3.0 go.uber.org/zap v1.26.0 google.golang.org/grpc v1.60.1 ) diff --git a/config/configgrpc/go.sum b/config/configgrpc/go.sum index f62f0924caa..bf1c091aa8f 100644 --- a/config/configgrpc/go.sum +++ b/config/configgrpc/go.sum @@ -289,6 +289,7 @@ go.opentelemetry.io/otel/sdk/metric v1.22.0/go.mod h1:KjQGeMIDlBNEOo6HvjhxIec1p/ go.opentelemetry.io/otel/trace v1.22.0 h1:Hg6pPujv0XG9QaVbGOBVHunyuLcCC3jN7WEhPx83XD0= go.opentelemetry.io/otel/trace v1.22.0/go.mod h1:RbbHXVqKES9QhzZq/fE5UnOSILqRt40a21sPw2He1xo= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= diff --git a/config/configgrpc/package_test.go b/config/configgrpc/package_test.go new file mode 100644 index 00000000000..519657748da --- /dev/null +++ b/config/configgrpc/package_test.go @@ -0,0 +1,17 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package configgrpc + +import ( + "testing" + + "go.uber.org/goleak" +) + +// The IgnoreTopFunction call prevents catching the leak generated by opencensus +// defaultWorker.Start which at this time is part of the package's init call. +// See https://github.com/open-telemetry/opentelemetry-collector/issues/9165#issuecomment-1874836336 for more context. +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start")) +}