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

[BUG] fatal error concurrent map iteration of ctx.baggage with tracer inject #2528

Closed
elijahj19 opened this issue Jan 22, 2024 · 2 comments
Closed
Labels
bug unintended behavior that has to be fixed

Comments

@elijahj19
Copy link

elijahj19 commented Jan 22, 2024

Version of dd-trace-go

v1.59.0

Describe what happened:

Hi team, a project using this package 1.57.0 (later upgraded to 1.59.0) began to crash because of concurrent map iteration.

In all cases of the Fatal concurrent map errors, the stack traces of crashes showed tracer.Inject and mentioned this line here in which there is a raw map iteration of ctx.baggage (textmap.go#L367).

However, ctx.baggage should be protected by a mutex as commented here (spancontext.go#L99). Seemingly the concurrent safe ForeachBaggageItem should be used or the mutex should be locked instead of a raw iteration.

Describe what you expected:
No concurrent map iteration/write. Accessing map using mutex or concurrent safe methods.

Steps to reproduce the issue:

I've been able to locally reproduce the data race with the following code and running go run -race main.go

tracer.Start()
span, _ := tracer.StartSpanFromContext(context.Background(), "main")
defer span.Finish()

var wg sync.WaitGroup
for i := 0; i < 500; i++ {
  wg.Add(1)
  i := i
  go func(val int) {
    defer wg.Done()
    span.SetBaggageItem("val", fmt.Sprintf("%d", val))

    traceContext := map[string]string{}
    _ = tracer.Inject(span.Context(), tracer.TextMapCarrier(traceContext))
  }(i)
}

wg.Wait()

Additional environment details (Version of Go, Operating System, etc.): 1.20

@elijahj19 elijahj19 added the bug unintended behavior that has to be fixed label Jan 22, 2024
@github-actions github-actions bot added the needs-triage New issues that have not yet been triaged label Jan 22, 2024
@darccio darccio removed the needs-triage New issues that have not yet been triaged label Jan 26, 2024
darccio added a commit that referenced this issue Jan 26, 2024
@darccio
Copy link
Contributor

darccio commented Jan 26, 2024

Thanks @elijahj19 for the report. This seems to be related to #2518. Both have been unified as a single issue and fixed by #2521, where we included your test. Closing to track both issues in the earliest report.

@darccio darccio closed this as not planned Won't fix, can't repro, duplicate, stale Jan 26, 2024
@darccio
Copy link
Contributor

darccio commented Feb 8, 2024

Released as part of v1.60.1 cc @elijahj19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug unintended behavior that has to be fixed
Projects
None yet
Development

No branches or pull requests

2 participants