Open phrinx opened 9 years ago
Yeah the upstream middleware is using a global stack, which is clearly not thread-safe. The bug needs to be fixed in the finagle-thrift gem
do you guys think this will work? I'm also not sure if twitter will be willing to install the thread_safe gem.
module Trace extend self
@mutex = Mutex.new
def init
@mutex.synchronize do
@stack ||= ThreadSafe::Array.new
end
end
end
Nope, this is still storing the stack in a global.
You need to update the stack access method to pull from a thread-specific place -- NOT @stack.
module Trace extend self
..
def stack
Thread.current[:trace_stack] ||= []
end
end
Thanks for the help guys, here's the PR to address this. https://github.com/twitter/finagle/pull/363
I ran into a problem where error was raised inside zipkin rack middleware - here the stack:
After talking to @Oscil8 it seems the 'finagle-thrift' middleware is not thread-safe (e.g. when used in jruby environment) since its using a global common stack (https://github.com/twitter/finagle/blob/master/finagle-thrift/src/main/ruby/lib/finagle-thrift/trace.rb#L6)