Open xuminwlt opened 2 years ago
It's not a bug, but rather a missing feature -- we simply don't have an instrumentation for Guava's EventBus
.
Thanks, i have read the code of the EventBus LegacyAsyncDispatcher
. There is a queue and a while {} scope defined in
private final ConcurrentLinkedQueue<EventWithSubscriber> queue =
Queues.newConcurrentLinkedQueue();
---
EventWithSubscriber e;
while ((e = queue.poll()) != null) {
e.subscriber.dispatchEvent(e.event);
}
And the thread Event run path will be:
Main Thread A(Tomcat Http Thread) do post(Event) -> queue.add(Event)
-> Thread B(Tomcat Http Thread) poll the Event
-> Thread B do Executor.execute()
-> Thread A do something other
-> Thread B do something other
When Thread B do post
got the Event from Thread A and do dispatch (Executor.execute), Thread B also have other thing todo. The Thread B
context need keep it's own Context.
The Thread B
may do something like:
1. Spring Controller got a API call
2. EventBus post
2.0 EventBus poll a Event1(From Thread B)
2.0.1 Eventbus dispatch(Executor.execute-1) -> subscribe.doSomething()
2.1 EventBus poll a Event1(From Thread A)
2.1.1 EventBus dispatch(Executor.execute-2) -> subscribe.doSomething()
3 okhttp -> other thing
In my option. Enter the eventbus dispatch scope, store the current snapshot context, and wrap the main thread context to the event. Exit the eventbus scopre, set the snapshot context to current.
It's like a thread-cross producer-consumer question. any idea to do it?
Describe the bug
A simple demo use -javaagent with 1.15.0 version.
Steps to reproduce
eventBusPublisher.publish(1);
Can't get
TraceId
in subscribe method.But I can get
TraceId
in normal executor.execute()I have got the code in guava , It's also use the same class and method
executor.execute(
.What did you expect to see? A clear and concise description of what you expected to see.
Why i get different result.
What did you see instead? A clear and concise description of what you saw instead.
What version are you using? (e.g.,
v1.15.0
, ``, etc)Environment Compiler: (e.g., "AdoptOpenJDK 11.0.6") OS: (e.g., "MacOS") Runtime (if different from JDK above): (e.g., "Oracle JRE 8u251")