Skip to content

Conversation

@lukasbindreiter
Copy link
Contributor

Fix nil dereference panic when using the clickhouse exporter with the clickhouse.json feature gate enabled.

Description

The recent refactoring in #43518 introduced a variable shadowing bug:

exp := newLogsExporter(set.Logger, c)
startOpt := exporterhelper.WithStart(exp.start)
if featureGateJSON.IsEnabled() {
    // here is the bug, below line creates a new variable, in the scope of the if
    // the outer `exp` variable still points to the newLogsExporter
    exp := newLogsJSONExporter(set.Logger, c)
    // without this line here we even would have gotten a compiler error that exp is unused
    startOpt = exporterhelper.WithStart(exp.start)
}


return exporterhelper.NewLogs(
		ctx,
		set,
		cfg,
        // this always points to the newLogsExporter, and not as intended to the
        // JSON exporter in case the feature gate is set
		exp.pushLogsData,

// ...

Since exp.start is never called for that, this results in the following panic during runtime, because exp.db is nil.

"}, "otelcol.component.id": "otlp/hyperdx", "otelcol.component.kind": "receiver", "endpoint": "[::]:4318"}
2025-10-22T13:53:30.234Z        info    service@v0.138.0/service.go:245 Everything is ready. Begin running and processing data. {"resource": {"service.instance.id": "1e79a701-9f1d-4434-94f8-5154dfe70543", "service.name": "otelcol-contrib", "service.version": "0.138.0"}}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0x1deb510]

goroutine 199 [running]:
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/clickhouseexporter.(*tracesExporter).pushTraceData(0x4000fc5ef0, {0xbac9cc8?, 0x4000a12150?}, {0x4000565a28?, 0x40016c8e68?})
        github.com/open-telemetry/opentelemetry-collector-contrib/exporter/clickhouseexporter@v0.138.0/exporter_traces.go:71 +0x50
go.opentelemetry.io/collector/consumer.ConsumeTracesFunc.ConsumeTraces(0x4000a12160?, {0xbac9cc8?, 0x4000a12150?}, {0x4000565a28?, 0x40016c8e68?})
        go.opentelemetry.io/collector/consumer@v1.44.0/traces.go:27 +0x44

My fix here was to define a common interface for both exporters, so that the exp variable can be re-assigned from within the if scopes.

Alternatively, also the refactoring could be reverted, or both exp.pushLogsData and exp.shutdown could be assigned to a helper variable similar to what is done currently already with exp.start

@lukasbindreiter lukasbindreiter requested review from a team and dmitryax as code owners October 22, 2025 15:35
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 22, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: ChrsMark / name: Christos Markou (ba36c4d)

@github-actions github-actions bot added the first-time contributor PRs made by new contributors label Oct 22, 2025
@github-actions
Copy link
Contributor

Welcome, contributor! Thank you for your contribution to opentelemetry-collector-contrib.

Important reminders:

A maintainer will review your pull request soon. Thank you for helping make OpenTelemetry better!

@lukasbindreiter
Copy link
Contributor Author

@Frapschen

Copy link
Contributor

@Frapschen Frapschen left a comment

Choose a reason for hiding this comment

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

@lukasbindreiter Good catch. LGTM

@dmitryax
Copy link
Member

@lukasbindreiter please add a changelog item

@lukasbindreiter
Copy link
Contributor Author

@dmitryax added a changelog entry 👍

@ChrsMark ChrsMark added the ready to merge Code review completed; ready to merge by maintainers label Oct 23, 2025
@github-actions
Copy link
Contributor

Welcome, contributor! Thank you for your contribution to opentelemetry-collector-contrib.

Important reminders:

A maintainer will review your pull request soon. Thank you for helping make OpenTelemetry better!

@ChrsMark
Copy link
Member

Should be ready to go if CI goes green. Thank's @lukasbindreiter!

@songy23 songy23 merged commit b827c75 into open-telemetry:main Oct 23, 2025
189 checks passed
@github-actions github-actions bot added this to the next release milestone Oct 23, 2025
@otelbot
Copy link
Contributor

otelbot bot commented Oct 23, 2025

Thank you for your contribution @lukasbindreiter! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey. If you are getting started contributing, you can also join the CNCF Slack channel #opentelemetry-new-contributors to ask for guidance and get help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

exporter/clickhouse first-time contributor PRs made by new contributors ready to merge Code review completed; ready to merge by maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants