Conversation
|
I'll have to look closer at what's happening with the |
|
Changing the Now I'm trying to figure out if I can use Maybe we'll have to just rework this to not hold onto the locks while calling out to opentelemetry. |
99e90ab to
b08339b
Compare
|
@bantonsson if you have some time, would you mind taking a look? This reworks the way you added the method to get to OpenTelemetry context from The solution right now has pretty bad performance regression (one benchmark went up by 23 %) and I hope to get that a bit under control, but in the worst case, bad performance sounds better than a deadlock. |
b08339b to
eb0207f
Compare
|
Hey @mladedav. I completely missed this notification. I'll try to look at it today or tomorrow. |
| std::thread_local! { | ||
| static INSIDE_TRACING: AtomicBool = const { AtomicBool::new(false) } | ||
| } |
There was a problem hiding this comment.
Since this is a thread local, it will only be accessed by the current thread, so it doesn't need atomic ordering.
| std::thread_local! { | |
| static INSIDE_TRACING: AtomicBool = const { AtomicBool::new(false) } | |
| } | |
| std::thread_local! { | |
| static INSIDE_TRACING: Cell<bool> = const { Cell::new(false) } | |
| } |
Motivation
There is a potential deadlock described in #250 where we lock
ExtensionsMutwhen entering a span, we letopentelemetryactivate the context, it tries to log throughtracingin that operation which in turn callson_eventin this layer and we try to lockExtensionsMutagain.Solution
Instead of accessing span's internal state through
ExtensionsMut, we store anArc<Mutex<OtelData>>, clone theArcand then lock it to access it. This allows us to hold onto the state without deadlocking when other layers try to lock the extensions in re-entrant calls.There's a test to check for this but it needs to be run with
RUSTFLAGS='--cfg reentrant_tracing_test'environment. I did not put that into the CI because changing the environment forces recompilation of every dependency. So I'm still looking whether I'm able to do this a bit better or if I'll just drop the test.