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

Methods returning TemplateInstance reported as not blocking #36592

Closed
computerlove opened this issue Oct 20, 2023 · 5 comments · Fixed by #37734
Closed

Methods returning TemplateInstance reported as not blocking #36592

computerlove opened this issue Oct 20, 2023 · 5 comments · Fixed by #37734
Labels
area/qute The template engine area/resteasy-reactive kind/bug Something isn't working
Milestone

Comments

@computerlove
Copy link
Contributor

computerlove commented Oct 20, 2023

Describe the bug

When adding @RunOnVirtualThread on a method returning TemplateInstance the application does not build, with exception:

java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
        [error]: Build step io.quarkus.resteasy.reactive.server.deployment.ResteasyReactiveProcessor#setupEndpoints threw an exception: java.lang.RuntimeException: java.lang.RuntimeException: Failed to process method 'no.nte.services.ucmeteringvalues.rest.AdminResource#cashflowevents'
        at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.createEndpoints(EndpointIndexer.java:325)
        at io.quarkus.resteasy.reactive.server.deployment.ResteasyReactiveProcessor.setupEndpoints(ResteasyReactiveProcessor.java:656)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:858)
        at io.quarkus.builder.BuildContext.run(BuildContext.java:282)
        at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
        at java.base/java.lang.Thread.run(Thread.java:1583)
        at org.jboss.threads.JBossThread.run(JBossThread.java:501)
Caused by: java.lang.RuntimeException: Failed to process method 'org.acme.SomePage#get'
        at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.createResourceMethod(EndpointIndexer.java:789)
        at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.createEndpoints(EndpointIndexer.java:414)
        at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.createEndpoints(EndpointIndexer.java:292)
        ... 10 more
Caused by: jakarta.enterprise.inject.spi.DeploymentException: Method 'get' of class 'org.acme.SomePage' is considered a non blocking method. @RunOnVirtualThread can only be used on  methods considered blocking
        at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.isRunOnVirtualThread(EndpointIndexer.java:853)
        at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.createResourceMethod(EndpointIndexer.java:729)
        ... 12 more

Expected behavior

The application builds, and invokation is done on virtual thread.

Actual behavior

Application does not build

How to Reproduce?

Use the app generator, generate a app with quarkus-resteasy-reactive-qute. Add @RunOnVirtualThread in SomePage on class or method level.

Output of uname -a or ver

linux

Output of java -version

21

Quarkus version or git rev

2.4.2

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

Apache Maven 3.9.3

Additional information

Screenshot from 2023-10-20 10-45-19

@computerlove computerlove added the kind/bug Something isn't working label Oct 20, 2023
@computerlove
Copy link
Contributor Author

Looking closer at this it seems that this is intentional. ResteasyReactiveQuteProcessor has

@BuildStep
NonBlockingReturnTypeBuildItem nonBlockingTemplateInstance() {
    return new NonBlockingReturnTypeBuildItem(TEMPLATE_INSTANCE);
}

Adding @Blocking to the class fixes the problem.

@geoand Should this behavior be documented in the Qute documentation, perhaps a better error message on build failure?

@quarkus-bot
Copy link

quarkus-bot bot commented Oct 26, 2023

/cc @FroMage (resteasy-reactive), @stuartwdouglas (resteasy-reactive)

@geoand geoand added the area/qute The template engine label Oct 26, 2023
@geoand
Copy link
Contributor

geoand commented Oct 26, 2023

@computerlove I think we should do both.

cc @mkouba

@mkouba
Copy link
Contributor

mkouba commented Oct 26, 2023

Well, the error message from the description is not about Qute and TemplateInstance at all: jakarta.enterprise.inject.spi.DeploymentException: Method 'get' of class 'org.acme.SomePage' uses @RunOnVirtualThread but the target JDK version doesn't support virtual threads. Please configure your build tool to target Java 19 or above.

Anyway, I'm not so sure it was a good idea to produce the NonBlockingReturnTypeBuildItem for TemplateInstance. It's not an async type per se so it's a little bit confusing. @geoand WDYT?

@computerlove
Copy link
Contributor Author

computerlove commented Oct 27, 2023

It at least looks like I was in a confused state when creating the sample. The original exception is not the correct one.
I have updated it now.

The core exception is

Caused by: jakarta.enterprise.inject.spi.DeploymentException: Method 'get' of class 'org.acme.SomePage' is considered a non blocking method. @RunOnVirtualThread can only be used on methods considered blocking

Yeah, I had to look at ResteasyReactiveProcessor and ResteasyReactiveQuteProcessor for a long time before realizing why

public TemplateInstance get() { ... }

is considered blocking.

mkouba added a commit to mkouba/quarkus that referenced this issue Dec 14, 2023
- resource methods returing TemplateInstance are considered non-blocking
- fixes quarkusio#36592
mkouba added a commit to mkouba/quarkus that referenced this issue Dec 14, 2023
- resource methods returing TemplateInstance are considered non-blocking
- fixes quarkusio#36592
@quarkus-bot quarkus-bot bot added this to the 3.7 - main milestone Dec 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/qute The template engine area/resteasy-reactive kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants