question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MP Context ThreadContext isn't propagated properly with @RequestScoped

See original GitHub issue

Describe 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:open
  • Created 2 years ago
  • Reactions:1
  • Comments:12 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
gsmetcommented, Dec 12, 2022

@sdaschner could you check if this is still an issue with latest Quarkus? A lot of changes have been made in this area.

0reactions
quarkus-bot[bot]commented, Dec 12, 2022
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found