Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quarkus Ignores CurrentThreadContext on Blocking Methods Using SmallRye Reactive Messaging #40559

Open
gilday opened this issue May 10, 2024 · 1 comment

Comments

@gilday
Copy link

gilday commented May 10, 2024

Describe the bug

In an application that uses SmallRye Reactive Messaging, a channel consuming method may affect the contexts propagated to it using the @CurrentThreadContext annotation. However, when the channel consuming method is also annotated with @Blocking, the configuration in the @CurrentThreadContext annotation seems to be ignored.

@Path("/hello")
class GreetingResource {

  @Channel("greeting")
  Emitter<String> emitter;

  @POST
  @Consumes(MediaType.TEXT_PLAIN)
  public void hello(String body) {
    emitter.send(body);
  }
}

class GreetingProcessor {

  @Inject RequestContextController controller;
  @Inject Logger logger;

  @Blocking // CDI context is not cleared for blocking methods, removing this annotation avoids the IllegalStateException
  @CurrentThreadContext(cleared = ThreadContext.CDI)
  @Incoming("greeting")
  void process(String name) {
    if (!controller.activate()) {
      throw new IllegalStateException("Request context is already active");
    }

Expected behavior

The current context in the channel consuming method should be affected by the @CurrentThreadContext annotation.

Actual behavior

The context is propagated to the channel consuming method as if the @CurrentThreadContext annotation were not present.

How to Reproduce?

Small example application attached.

  1. Run the test and note that SmallRye Reactive Messaging logs that the process method throws the IllegalStateException that indicates the request context is active.
  2. Remove the @Blocking annotations from the process method.
  3. Re-run the test and note that no IllegalStateException is logged, because the CDI context has been cleared, so the RequestContextController reference in process may create a new request scope.

quarkus-emitter-new-request-context.zip

Output of uname -a or ver

Darwin pixee-mbp-gilday.localdomain 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:10:42 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6000 arm64

Output of java -version

openjdk version "21.0.1" 2023-10-17 LTS OpenJDK Runtime Environment Temurin-21.0.1+12 (build 21.0.1+12-LTS) OpenJDK 64-Bit Server VM Temurin-21.0.1+12 (build 21.0.1+12-LTS, mixed mode)

Quarkus version or git rev

3.10.0

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.9.6 (bc0240f3c744dd6b6ec2920b3cd08dcc295161ae) Maven home: /Users/jgilday/.m2/wrapper/dists/apache-maven-3.9.6-bin/3311e1d4/apache-maven-3.9.6 Java version: 21.0.1, vendor: Eclipse Adoptium, runtime: /Library/Java/JavaVirtualMachines/temurin-21.jdk/Contents/Home Default locale: en_US, platform encoding: UTF-8 OS name: "mac os x", version: "14.4.1", arch: "aarch64", family: "mac"

Additional information

No response

@quarkus-bot
Copy link

quarkus-bot bot commented May 10, 2024

/cc @Ladicek (smallrye), @cescoffier (reactive-messaging), @jmartisk (smallrye), @ozangunalp (reactive-messaging), @phillip-kruger (smallrye), @radcortez (smallrye)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant