Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: lock accesses to encoder in json stdout exporter to prevent crash #2265

Merged
merged 5 commits into from Sep 30, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions exporters/stdout/stdouttrace/trace.go
Expand Up @@ -49,6 +49,7 @@ func New(options ...Option) (*Exporter, error) {
// Exporter is an implementation of trace.SpanSyncer that writes spans to stdout.
type Exporter struct {
encoder *json.Encoder
encoderMu sync.Mutex
timestamps bool

stoppedMu sync.RWMutex
Expand Down Expand Up @@ -83,6 +84,8 @@ func (e *Exporter) ExportSpans(ctx context.Context, spans []trace.ReadOnlySpan)
}

// Encode span stubs, one by one
e.encoderMu.Lock()
Aneurysm9 marked this conversation as resolved.
Show resolved Hide resolved
defer e.encoderMu.Unlock()
if err := e.encoder.Encode(stub); err != nil {
return err
}
Expand Down