Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sdk/trace/simple_span_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ func (ssp *simpleSpanProcessor) OnEnd(s ReadOnlySpan) {

// 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).

return nil
}
var err error
ssp.stopOnce.Do(func() {
stopFunc := func(exp SpanExporter) (<-chan error, func()) {
Expand Down
6 changes: 5 additions & 1 deletion sdk/trace/simple_span_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,13 @@ func TestNewSimpleSpanProcessor(t *testing.T) {
}

func TestNewSimpleSpanProcessorWithNilExporter(t *testing.T) {
if ssp := NewSimpleSpanProcessor(nil); ssp == nil {
ssp := NewSimpleSpanProcessor(nil)
if ssp == nil {
t.Error("failed to create new SimpleSpanProcessor with nil exporter")
}
if err := ssp.Shutdown(t.Context()); err != nil {
t.Errorf("Shutdown with nil exporter should return nil, got %v", err)
}
}

func TestSimpleSpanProcessorOnEnd(t *testing.T) {
Expand Down
Loading