MP Context ThreadContext isn't propagated properly with @RequestScoped
See original GitHub issueDescribe the bug
The ThreadContext
from MP doesn’t reliably capture the context of beans that include a @RequestScoped
bean.
Not sure if I’m missing something, but the example (that I’ve tested with other MP impls) described here doesn’t work with Quarkus.
Expected behavior
No response
Actual behavior
No response
How to Reproduce?
@ApplicationScoped
@Path("contexts/example")
public class ThreadContextExampleResource {
@Inject
ExampleStore exampleStore;
@Inject
ThreadContext threadContext;
@Inject
ManagedExecutor mes;
@Inject
Notifier notifier;
@PUT
public void setExample(String example) {
exampleStore.setExample(example);
mes.execute(threadContext.contextualRunnable(notifier::notifyAbout));
}
}
@RequestScoped
class ExampleStore {
private String example;
public String getExample() {
return example;
}
public void setExample(String example) {
this.example = example;
}
}
@Dependent
class Notifier {
@Inject
ExampleStore exampleStore;
public void notifyAbout() {
LockSupport.parkNanos(200_000_000L);
System.out.println("New example: " + exampleStore.getExample());
}
}
Invoking curl localhost:8080/contexts/example -i -XPUT -H 'Content-Type: text/plain' -d 'foobar'
produces empty logs, if the processing takes longer (our wait for 200ms):
New example: null
Output of uname -a
or ver
No response
Output of java -version
No response
GraalVM version (if different from Java)
No response
Quarkus version or git rev
2.0.2.Final
Build tool (ie. output of mvnw --version
or gradlew --version
)
No response
Additional information
It didn’t make a difference whether the ThreadContext
or ManagedExecutor
were obtained programmatically or via injection.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:12 (11 by maintainers)
Top Results From Across the Web
Context Propagation in Quarkus
Many Quarkus extensions require those contextual objects to operate properly: RESTEasy Reactive, ArC and Transaction for example. If you write reactive/async ...
Read more >ThreadContext.REQUEST · Issue #134 - GitHub
Currently it's possible to control propagation of contexts via ... These objects are not bound to any CDI context, and are propagated by...
Read more >ThreadContext (MicroProfile Context Propagation)
Identifier for all available thread context types which are not specified individually under cleared , propagated , or unchanged .
Read more >eclipse/microprofile-concurrency - Gitter
my understanding was that a CF we got via ThreadContext would propagate context by capturing it and restoring it for the callbacks.
Read more >Concurrency with MicroProfile Context Propagation
ThreadContext interface to pre-contextualize completion stage actions. This is useful when you have an unmanaged completion stage that is not thread-context ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@sdaschner could you check if this is still an issue with latest Quarkus? A lot of changes have been made in this area.
/cc @FroMage, @manovotn