Skip to content

fix(sdk/trace): guard Shutdown against nil exporter - #8901

Open
AruneshDwivedi wants to merge 2 commits into
open-telemetry:mainfrom
AruneshDwivedi:fix-nil-shutdown
Open

fix(sdk/trace): guard Shutdown against nil exporter#8901
AruneshDwivedi wants to merge 2 commits into
open-telemetry:mainfrom
AruneshDwivedi:fix-nil-shutdown

Conversation

@AruneshDwivedi

Copy link
Copy Markdown

NewSimpleSpanProcessor(nil) stores a nil exporter but Shutdown later dereferences it without a nil check, panicking and terminating the host process during telemetry shutdown.

Add an early return when ssp.exporter is nil, matching the constructor tested behavior of accepting a nil exporter. Extend the existing test to verify Shutdown does not panic.

NewSimpleSpanProcessor(nil) stores a nil exporter but Shutdown later
dereferences it without a nil check, panicking and terminating the
host process during telemetry shutdown.

Add an early return when ssp.exporter is nil, matching the constructor's
tested behavior of accepting a nil exporter. Add a regression test.

Signed-off-by: Arunesh Dwivedi <arunesh@example.com>
The nil-exporter constructor test declared ssp inside the if-condition,
making it unreachable when checking Shutdown. Hoist the declaration so
the regression test actually exercises Shutdown(nil).

Signed-off-by: Arunesh Dwivedi <arunesh@example.com>

// Shutdown shuts down the exporter this SimpleSpanProcessor exports to.
func (ssp *simpleSpanProcessor) Shutdown(ctx context.Context) error {
if ssp.exporter == nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reading ssp.exporter here without acquiring ssp.exporterMu can lead to a data race with concurrent calls. Consider moving the nil check inside stopOnce.Do after acquiring ssp.exporterMu (e.g. returning early if exp == nil).

@codecov

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.4%. Comparing base (1ad6638) to head (a760176).

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #8901   +/-   ##
=====================================
  Coverage   88.4%   88.4%           
=====================================
  Files        331     331           
  Lines      21001   21003    +2     
=====================================
+ Hits       18572   18575    +3     
+ Misses      2429    2428    -1     
Files with missing lines Coverage Δ
sdk/trace/simple_span_processor.go 93.4% <100.0%> (+0.2%) ⬆️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants