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 writes (*span).SetAttributes #2518

Closed
theFong opened this issue Jan 17, 2024 · 2 comments · Fixed by #2521
Closed

[BUG] fatal error: concurrent map writes (*span).SetAttributes #2518

theFong opened this issue Jan 17, 2024 · 2 comments · Fixed by #2521
Labels
bug unintended behavior that has to be fixed

Comments

@theFong
Copy link

theFong commented Jan 17, 2024

Version of dd-trace-go

v1.59.0

Describe what happened:

Calling span.SetAttributes concurrently results in fatal error: concurrent map writes

Describe what you expected:
The span does not seem thread-safe for concurrent reads and writes and it is unclear whether this is the intended behavior.

Steps to reproduce the issue:

	ctx, span = tracer.Start(ctx, "test")
	defer span.End()

	numberOfWorkers := 100
	workerIDs := []int{}
	for i := 0; i < numberOfWorkers; i++ {
		workerIDs = append(workerIDs, i)
	}
	_, err = collections.ParallelWorkerMapE(workerIDs, func(i int) (any, error) { // this is a custom method that loops over a slice and runs a function in parallel
		for {
			span.SetAttributes(attribute.Float64("workerID", float64(i)))
		}
	}, numberOfWorkers)
	if !assert.NoError(t, err) {
		return
	}

Additional environment details (Version of Go, Operating System, etc.):
go version go1.20 linux/amd64

@theFong theFong added the bug unintended behavior that has to be fixed label Jan 17, 2024
@github-actions github-actions bot added apm:ecosystem contrib/* related feature requests or bugs needs-triage New issues that have not yet been triaged labels Jan 17, 2024
@darccio darccio removed apm:ecosystem contrib/* related feature requests or bugs needs-triage New issues that have not yet been triaged labels Jan 19, 2024
@darccio
Copy link
Member

darccio commented Jan 19, 2024

Reproduced:

func TestConcurrentSetAttributes(t *testing.T) {
	tp := NewTracerProvider()
	otel.SetTracerProvider(tp)
	tr := otel.Tracer("")

	_, span := tr.Start(context.Background(), "test")
	defer span.End()

	var wg sync.WaitGroup
	for i := 0; i < 100; i++ {
		wg.Add(1)
		i := i
		go func(val int) {
			defer wg.Done()
			span.SetAttributes(attribute.Float64("workerID", float64(i)))
		}(i)
	}
}

@darccio
Copy link
Member

darccio commented Feb 8, 2024

Released as part of v1.60.1 cc @theFong

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

Successfully merging a pull request may close this issue.

2 participants