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

[exporter/datadog] Avoid logging in chain provider goroutines to avoid data race #24899

Merged
merged 3 commits into from
Aug 4, 2023
Merged
Changes from 1 commit
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
Next Next commit
[exporter/datadog] Avoid logging in chain provider goroutines to avoi…
…d data race
  • Loading branch information
mx-psi committed Aug 4, 2023
commit 6a6df33e250722e7adf6e6bb461bcf112258404f
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,28 @@ func (p *chainProvider) Source(ctx context.Context) (source.Source, error) {
for i, source := range p.priorityList {
provider := p.providers[source]
replies[i] = make(chan reply)

p.logger.Debug("Trying out source provider", zap.String("provider", source))
go func(i int, source string) {
zapProvider := zap.String("provider", source)
p.logger.Debug("Trying out source provider", zapProvider)

src, err := provider.Source(ctx)
if err != nil {
p.logger.Debug("Unavailable source provider", zapProvider, zap.Error(err))
}

replies[i] <- reply{src: src, err: err}
}(i, source)
}

// Check provider responses in order to ensure priority
for i, ch := range replies {
reply := <-ch
if reply.err != nil {
// Provider was unavailable, error was logged on goroutine
continue
}
zapProvider := zap.String("provider", p.priorityList[i])
select {
case <-ctx.Done():
return source.Source{}, fmt.Errorf("context was cancelled: %w", ctx.Err())
case reply := <-ch:
if reply.err != nil {
p.logger.Debug("Unavailable source provider", zapProvider, zap.Error(reply.err))
continue
}

p.logger.Info("Resolved source",
zap.String("provider", p.priorityList[i]), zap.Any("source", reply.src),
)
return reply.src, nil
p.logger.Info("Resolved source", zapProvider, zap.Any("source", reply.src))
return reply.src, nil
}
}

return source.Source{}, fmt.Errorf("no source provider was available")
Expand Down
Loading