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

java.lang.IllegalStateException: Blocking REST client call made fr om the event loop in restclient-reactive #17084

Closed
hantsy opened this issue May 8, 2021 · 4 comments
Labels
area/rest-client kind/bug Something isn't working triage/out-of-date This issue/PR is no longer valid or relevant

Comments

@hantsy
Copy link
Contributor

hantsy commented May 8, 2021

Discussed in this topic: https://quarkusio.zulipchat.com/#narrow/stream/187030-users/topic/Blocking.20REST.20client.20call.20made.20from.20the.20event.20loop/near/237832543

I used the following stack to create a pure reactive rest client.

  • Quarkus 1.13.3.Final
  • Restclient reative/Resteasy Reactive

The rest Client interface.

@Path("/posts")
@RegisterRestClient()
@RegisterProvider(PostResponseExceptionMapper.class)
public interface PostResourceClient {

    @Path("count")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    Uni<Long> countAllPosts(@QueryParam("q") String q);

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    Multi<List<Post>> getAllPosts(
            @QueryParam("q") String q,
            @QueryParam("offset") @DefaultValue("0") int offset,
            @QueryParam("limit") @DefaultValue("10") int limit
    );

    @GET
    @Path("{id}")
    @Produces(MediaType.APPLICATION_JSON)
    Uni<Post> getPostById(@PathParam("id") String id);
}

And created a resource to call it.

@Path("/api")
@RequestScoped
public class PostController {
    @Inject
    @RestClient
    PostResourceClient client;

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Uni<PostPage> getAllPosts(
            @QueryParam("q") String q,
            @QueryParam("offset") @DefaultValue("0") int offset,
            @QueryParam("limit") @DefaultValue("10") int limit
    ) {
        return Uni.combine().all()
                .unis(
                        this.client.getAllPosts(q, offset, limit).collect().asList(),
                        this.client.countAllPosts(q)
                )
                .combinedWith(
                        results -> PostPage.of((List<Post>) results.get(0), (Long) results.get(1))
                );
    }

    @GET
    @Path("{id}")
    @Produces(MediaType.APPLICATION_JSON)
    public Uni<Post> getPost(@PathParam("id") String id) {
        return this.client.getPostById(id);
    }
}

Tried to run the application, and send a request from curl. and got the following example.

2021-05-08 13:27:54,073 ERROR [org.jbo.res.rea.ser.cor.ExceptionMapping] (vert.x-eventloop-thread-1) Request failed : java.lang.IllegalStateException: Blocking REST client call made fr
om the event loop. If the code is executed from a RESTEasy Reactive resource, either annotate the resource method with `@Blocking` or use non-blocking client calls.
        at org.jboss.resteasy.reactive.client.impl.InvocationBuilderImpl.unwrap(InvocationBuilderImpl.java:198)
        at org.jboss.resteasy.reactive.client.impl.InvocationBuilderImpl.method(InvocationBuilderImpl.java:319)
        at com.example.demo.PostResourceClient$$QuarkusRestClientInterface.getAllPosts(PostResourceClient$$QuarkusRestClientInterface.zig:468)
        at com.example.demo.PostResourceClient$$CDIWrapper.getAllPosts(PostResourceClient$$CDIWrapper.zig:70)
        at com.example.demo.PostResourceClient$$CDIWrapper_Subclass.getAllPosts$$superaccessor1(PostResourceClient$$CDIWrapper_Subclass.zig:289)
        at com.example.demo.PostResourceClient$$CDIWrapper_Subclass$$function$$1.apply(PostResourceClient$$CDIWrapper_Subclass$$function$$1.zig:51)
        at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
        at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.proceed(InvocationInterceptor.java:63)
        at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.monitor(InvocationInterceptor.java:49)
        at io.quarkus.arc.runtime.devconsole.InvocationInterceptor_Bean.intercept(InvocationInterceptor_Bean.zig:521)
        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.example.demo.PostResourceClient$$CDIWrapper_Subclass.getAllPosts(PostResourceClient$$CDIWrapper_Subclass.zig:242)
        at com.example.demo.PostController.getAllPosts(PostController.java:28)
        at com.example.demo.PostController_Subclass.getAllPosts$$superaccessor2(PostController_Subclass.zig:374)
        at com.example.demo.PostController_Subclass$$function$$2.apply(PostController_Subclass$$function$$2.zig:51)
        at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
        at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.proceed(InvocationInterceptor.java:63)
        at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.monitor(InvocationInterceptor.java:49)
        at io.quarkus.arc.runtime.devconsole.InvocationInterceptor_Bean.intercept(InvocationInterceptor_Bean.zig:521)
        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.example.demo.PostController_Subclass.getAllPosts(PostController_Subclass.zig:327)
        at com.example.demo.PostController_ClientProxy.getAllPosts(PostController_ClientProxy.zig:109)
        at com.example.demo.PostController$quarkusrestinvoker$getAllPosts_e86e499f776b53a0f1950570a1bd4434ea61b09b.invoke(PostController$quarkusrestinvoker$getAllPosts_e86e499f776b53a0
f1950570a1bd4434ea61b09b.zig:55)
        at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
        at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:7)
        at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:122)
        at org.jboss.resteasy.reactive.server.handlers.RestInitialHandler.beginProcessing(RestInitialHandler.java:47)
        at org.jboss.resteasy.reactive.server.vertx.ResteasyReactiveVertxHandler.handle(ResteasyReactiveVertxHandler.java:17)
        at org.jboss.resteasy.reactive.server.vertx.ResteasyReactiveVertxHandler.handle(ResteasyReactiveVertxHandler.java:7)
        at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1038)
        at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:137)
        at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:132)
        at io.quarkus.vertx.http.runtime.StaticResourcesRecorder.lambda$start$1(StaticResourcesRecorder.java:65)
        at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1038)
        at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:101)
        at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:132)
        at io.vertx.ext.web.handler.impl.StaticHandlerImpl.lambda$sendStatic$1(StaticHandlerImpl.java:206)
        at io.vertx.core.impl.ContextImpl.lambda$null$0(ContextImpl.java:327)
        at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:366)
        at io.vertx.core.impl.EventLoopContext.lambda$executeAsync$0(EventLoopContext.java:38)
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:831)

The latest reactive stack printed in the console when starting up the application.

Installed features: [cdi, jaxrs-client-reactive, mutiny, rest-client-reactive, rest-client-reactive-jackson, resteasy-r
eactive, smallrye-context-propagation]

The source codes: https://github.com/hantsy/quarkus-sandbox/tree/master/restclient-reactive

The target remote API is https://github.com/hantsy/quarkus-sandbox/tree/master/post-service

@hantsy hantsy added the kind/bug Something isn't working label May 8, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented May 8, 2021

/cc @michalszynkiewicz

@geoand
Copy link
Contributor

geoand commented May 8, 2021

Can you please try with Quarkus with #17095 applied to main and see if the problem persists?

@michalszynkiewicz
Copy link
Member

@hantsy do you still see this problem with 2.2?

@geoand
Copy link
Contributor

geoand commented Sep 30, 2021

Closing this as out of date. If this is still a problem, feel free to reopen or comment

@geoand geoand closed this as completed Sep 30, 2021
@geoand geoand added the triage/out-of-date This issue/PR is no longer valid or relevant label Sep 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/rest-client kind/bug Something isn't working triage/out-of-date This issue/PR is no longer valid or relevant
Projects
None yet
Development

No branches or pull requests

3 participants