From 67866cec024a7da7f7ab3dc962dfe61f0d160f0e Mon Sep 17 00:00:00 2001 From: Pavan Krishna Date: Tue, 29 Nov 2022 06:56:21 -0800 Subject: [PATCH] Fix nil panic from otlp exporter (#6633) * fix nil panic from otlp exporter. * fix nil panic from otlp exporter. * fix nil panic from otlp exporter. --- .chloggen/authpanic.yaml | 12 ++++++++++++ exporter/otlpexporter/factory_test.go | 5 +++-- exporter/otlpexporter/otlp.go | 6 ++++-- 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100755 .chloggen/authpanic.yaml diff --git a/.chloggen/authpanic.yaml b/.chloggen/authpanic.yaml new file mode 100755 index 00000000000..ff5f7229a6b --- /dev/null +++ b/.chloggen/authpanic.yaml @@ -0,0 +1,12 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: otlpexporter + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Fix nil panic from otlp exporter in case of errors during Start. + +# One or more tracking issues or pull requests related to the change +issues: [6633] + diff --git a/exporter/otlpexporter/factory_test.go b/exporter/otlpexporter/factory_test.go index 0f6f8bd29c1..9505a9f7d90 100644 --- a/exporter/otlpexporter/factory_test.go +++ b/exporter/otlpexporter/factory_test.go @@ -206,9 +206,10 @@ func TestCreateTracesExporter(t *testing.T) { err = consumer.Start(context.Background(), componenttest.NewNopHost()) if tt.mustFailOnStart { assert.Error(t, err) - return + } else { + assert.NoError(t, err) } - assert.NoError(t, err) + // Shutdown is called even when Start fails err = consumer.Shutdown(context.Background()) if err != nil { // Since the endpoint of OTLP exporter doesn't actually exist, diff --git a/exporter/otlpexporter/otlp.go b/exporter/otlpexporter/otlp.go index 08e36a2fbef..3694f8fb9bc 100644 --- a/exporter/otlpexporter/otlp.go +++ b/exporter/otlpexporter/otlp.go @@ -77,7 +77,6 @@ func (e *exporter) start(ctx context.Context, host component.Host) (err error) { if e.clientConn, err = e.config.GRPCClientSettings.ToClientConn(ctx, host, e.settings, grpc.WithUserAgent(e.userAgent)); err != nil { return err } - e.traceExporter = ptraceotlp.NewGRPCClient(e.clientConn) e.metricExporter = pmetricotlp.NewGRPCClient(e.clientConn) e.logExporter = plogotlp.NewGRPCClient(e.clientConn) @@ -90,7 +89,10 @@ func (e *exporter) start(ctx context.Context, host component.Host) (err error) { } func (e *exporter) shutdown(context.Context) error { - return e.clientConn.Close() + if e.clientConn != nil { + return e.clientConn.Close() + } + return nil } func (e *exporter) pushTraces(ctx context.Context, td ptrace.Traces) error {