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

IllegalStateException if method return type is CompletionStage<Xxx> using @CacheResult #23816

Closed
leotu opened this issue Feb 20, 2022 · 2 comments · Fixed by #24894
Closed

IllegalStateException if method return type is CompletionStage<Xxx> using @CacheResult #23816

leotu opened this issue Feb 20, 2022 · 2 comments · Fixed by #24894
Assignees
Labels
area/cache kind/bug Something isn't working
Milestone

Comments

@leotu
Copy link

leotu commented Feb 20, 2022

Describe the bug

Method return type is CompletionStage cause "The current thread cannot be blocked: vert.x-eventloop-thread-xx"

  // raise exception
 @CacheResult(cacheName = "/api/m/test/stage")
 @GET
 @Path("/stage")
 @Produces(MediaType.TEXT_PLAIN)
 public CompletionStage<String> stage() {
      return CompletableFuture.completedFuture("stage:" + LocalDateTime.now());
 }

Expected behavior

Should work when function return type CompletionStage Annotated with @CacheResult or @CacheInvalidate

Actual behavior

13:12:33.165 DEBUG [vert.x-eventloop-thread-8] [null:-1,null()] RoutingContext failure (500): java.lang.IllegalStateException: The current thread cannot be blocked: vert.x-eventloop-thread-8
	at io.smallrye.mutiny.operators.uni.UniBlockingAwait.await(UniBlockingAwait.java:30)
	at io.smallrye.mutiny.groups.UniAwait.atMost(UniAwait.java:65)
	at io.smallrye.mutiny.groups.UniAwait.indefinitely(UniAwait.java:46)
	at io.quarkus.cache.runtime.CacheResultInterceptor.intercept(CacheResultInterceptor.java:115)
	at io.quarkus.cache.runtime.CacheResultInterceptor_Bean.intercept(Unknown Source)
	at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
	at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
	at com.xgosh.test.TestResource_Subclass.stage(Unknown Source)
	at com.xgosh.test.TestResource_ClientProxy.stage(Unknown Source)
	at com.xgosh.test.TestResource$quarkusrestinvoker$stage_971e8502f0474c9186922d25a243c5718389abdd.invoke(Unknown Source)
	at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)

How to Reproduce?

Test Code

/**
 * <pre>
 * http://localhost:7070/api/m/test/normal
 * http://localhost:7070/api/m/test/uni
 * http://localhost:7070/api/m/test/stage
 * http://localhost:7070/api/m/test/stageBlocking
 * </pre>
 */
@RegisterForReflection
@ApplicationScoped
@Path("/api/m/test")
public class TestResource {

    /**
     * No error
     */
    @CacheResult(cacheName = "/api/m/test/normal")
    @GET
    @Path("/normal")
    @Produces(MediaType.TEXT_PLAIN)
    public String normal() {
        return "normal:" + LocalDateTime.now();
    }

    /**
     * No error
     */
    @CacheResult(cacheName = "/api/m/test/uni")
    @GET
    @Path("/uni")
    @Produces(MediaType.TEXT_PLAIN)
    public Uni<String> uni() {
        return Uni.createFrom().item("uni:" + LocalDateTime.now());
    }

    /**
     * Error
     */
    @CacheResult(cacheName = "/api/m/test/stage")
    @GET
    @Path("/stage")
    @Produces(MediaType.TEXT_PLAIN)
    public CompletionStage<String> stage() {
        return CompletableFuture.completedFuture("stage:" + LocalDateTime.now());
    }

    /**
     * No error
     */
    @CacheResult(cacheName = "/api/m/test/stageBlocking")
    @GET
    @Path("/stageBlocking")
    @Produces(MediaType.TEXT_PLAIN)
    @Blocking
    public CompletionStage<String> stageBlocking() {
        return CompletableFuture.completedFuture("stageBlocking:" + LocalDateTime.now());
    }

}

Output of uname -a or ver

No response

Output of java -version

openjdk version "17.0.2" 2022-01-18
OpenJDK Runtime Environment GraalVM CE 21.3.1 (build 17.0.2+8-jvmci-21.3-b09)
OpenJDK 64-Bit Server VM GraalVM CE 21.3.1 (build 17.0.2+8-jvmci-21.3-b09, mixed mode, sharing)

GraalVM version (if different from Java)

GraalVM CE 21.3.1

Quarkus version or git rev

2.7.1.Final

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

No response

Additional information

No response

@leotu leotu added the kind/bug Something isn't working label Feb 20, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Feb 20, 2022

/cc @gwenneg

@leotu
Copy link
Author

leotu commented Feb 20, 2022

Note:
Downgrade to version 2.6.3.Final, still failed
Downgrade to version 2.5.4.Final, works

@gwenneg gwenneg self-assigned this Feb 21, 2022
geoand added a commit to geoand/quarkus that referenced this issue Apr 20, 2022
geoand added a commit that referenced this issue Apr 20, 2022
Properly support CompletionStage as a return type in caching extension
@quarkus-bot quarkus-bot bot added this to the 2.9 - main milestone Apr 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cache kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants