Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

DATA RACE : span.context overwritten in span.SetBaggageItem() without any guards #526

Closed
keer25 opened this issue Aug 16, 2020 · 1 comment · Fixed by #544
Closed

DATA RACE : span.context overwritten in span.SetBaggageItem() without any guards #526

keer25 opened this issue Aug 16, 2020 · 1 comment · Fixed by #544

Comments

@keer25
Copy link

keer25 commented Aug 16, 2020

Problem : DATA RACE when setting baggage item and tag concurrently

In Version : 2.25.0

  • span.context is read in a lot of places without any mutex, while SetBaggageItem overwrites the context in bagge_setter.go
    span.context = span.context.WithBaggageItem(key, value)

WARNING: DATA RACE

Read at 0x00c0000824e0 by goroutine 45:
...../vendor/github.com/uber/jaeger-client-go.(*Span).isSamplingFinalized()
/home/paasuser/..../vendor/github.com/uber/jaeger-client-go/span.go:446 +0x3e
.../vendor/github.com/uber/jaeger-client-go.(*Span).setTagInternal()
/home/paasuser/..../vendor/github.com/uber/jaeger-client-go/span.go:107 +0x109
.../vendor/github.com/uber/jaeger-client-go.(*Span).SetTag()
/home/paasuser/src/.../vendor/github.com/uber/jaeger-client-go/span.go:99 +0x6c

Previous write at 0x00c0000824e0 by goroutine 46:
.../vendor/github.com/uber/jaeger-client-go.(*baggageSetter).setBaggage()
/home/paasuser/.../vendor/github.com/uber/jaeger-client-go/baggage_setter.go:54 +0x3ca
.../vendor/github.com/uber/jaeger-client-go.(*Span).SetBaggageItem()
/home/paasuser/.../vendor/github.com/uber/jaeger-client-go/tracer.go:470 +0xf3

Proposal

  • Don't overwrite context in baggage_setter.go
  • Use a sync.Map for storing baggage items, the change can touch 5 files where context.baggage is read and updated.

(OR)

  • Use locks in operation where span.context is accessed

Any open questions to address

  • I also don't fully understand why a new span context is allocated every time a baggage item is set. Is there any explicit need for that which I am not seeing?
  • I will be happy to create a PR for this if the above question is clarified.
yurishkuro pushed a commit that referenced this issue Aug 16, 2020
Reported in #526.

Signed-off-by: Yuri Shkuro <ys@uber.com>
yurishkuro pushed a commit that referenced this issue Aug 16, 2020
Per issue #526.

Signed-off-by: Yuri Shkuro <ys@uber.com>
@yurishkuro
Copy link
Member

Thanks for reporting. I added a unit test (currently disabled) that illustrates the race. We need to ensure that access to s.context is always done under read-lock, at minimum. I would like to see how it would affect a micro-benchmark.

To answer your question, I believe the intention was for Context object to not contain any lock objects, because it was designed to be passed by-value (a decision that I regret in retrospect, since it does not actually reduce memory allocations due to conversion to opentracing.SpanContext interface). Therefore, it must contain immutable baggage and perform copy-on-write (I just added comments about that - cf8927b).

keer25 added a commit to keer25/jaeger-client-go that referenced this issue Aug 25, 2020
This commit addresses data race issues where span.context is accessed without locks in methods which can be called concurrently with method setBaggageItem which modifies context

Per issue jaegertracing#526

Signed-off-by: Keerthana Selvakumar <keerukeerthana8@gmail.com>
keer25 added a commit to keer25/jaeger-client-go that referenced this issue Aug 25, 2020
This commit addresses data race issues where span.context is accessed without locks in methods which can be called concurrently with method setBaggageItem which modifies context

Per issue jaegertracing#526

Signed-off-by: Keerthana Selvakumar <keerukeerthana8@gmail.com>
keer25 added a commit to keer25/jaeger-client-go that referenced this issue Aug 25, 2020
This commit addresses data race issues where span.context is accessed without locks in methods which can be called concurrently with method setBaggageItem which modifies context

Resolves issue jaegertracing#526

Signe-off-by: Keerthana Selvakumar <keerukeerthana8@gmail.com>
keer25 added a commit to keer25/jaeger-client-go that referenced this issue Aug 25, 2020
This commit addresses data race issues where span.context is accessed without locks in methods which can be called concurrently with method setBaggageItem which modifies context

Resolves issue jaegertracing#526

Signed-off-by: Keerthana Selvakumar <keerukeerthana8@gmail.com>
keer25 added a commit to keer25/jaeger-client-go that referenced this issue Aug 25, 2020
This commit addresses data race issues where span.context is accessed without locks in methods which can be called concurrently with method setBaggageItem which modifies context

Per issue jaegertracing#526

Signed-off-by: Keerthana Selvakumar <keerukeerthana8@gmail.com>
keer25 added a commit to keer25/jaeger-client-go that referenced this issue Aug 26, 2020
This commit addresses data race issues where span.context is accessed without locks in methods which can be called concurrently with method setBaggageItem which modifies context

Per issue jaegertracing#526

Signed-off-by: Keerthana Selvakumar <keerukeerthana8@gmail.com>
keer25 added a commit to keer25/jaeger-client-go that referenced this issue Aug 26, 2020
This commit addresses data race issues where span.context is accessed without locks in methods which can be called concurrently with method setBaggageItem which modifies context

Per issue jaegertracing#526

Signed-off-by: Keerthana Selvakumar <keerukeerthana8@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants