Quarkus: Quarkus raises RuntimeException 'Error injecting...' when try to inject Singleton beans in Native when run within Docker container

Created on 1 Dec 2020  路  9Comments  路  Source: quarkusio/quarkus

Describe the bug
In a native application running in Docker, it seems the injection for Singleton beans don't work when I send a request:

2020-12-01 19:05:50,804 INFO  [io.quarkus] (main) quarkus-employee-istio 1.0.0 native (powered by Quarkus 1.10.2.Final) started in 0.099s. Listening on: http://0.0.0.0:8080
2020-12-01 19:05:50,804 INFO  [io.quarkus] (main) Profile prod activated. 
2020-12-01 19:05:50,804 INFO  [io.quarkus] (main) Installed features: [cdi, mutiny, reactive-pg-client, smallrye-context-propagation, smallrye-health, vertx, vertx-web]
2020-12-01 19:06:18,035 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (vert.x-eventloop-thread-1) HTTP Request to /api/v1/employee failed, error id: db1db295-e37d-4934-8477-cd3f51d9dadb-1: java.lang.RuntimeException: Error injecting com.serrodcal.service.EmployeeService com.serrodcal.resource.EmployeeResource.employeeService
    at com.serrodcal.resource.EmployeeResource_Bean.create(EmployeeResource_Bean.zig:148)
    at com.serrodcal.resource.EmployeeResource_Bean.create(EmployeeResource_Bean.zig:171)
    at io.quarkus.arc.impl.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:96)
    at io.quarkus.arc.impl.AbstractSharedContext.access$000(AbstractSharedContext.java:14)
    at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:29)
    at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:26)
    at io.quarkus.arc.impl.LazyValue.get(LazyValue.java:26)
    at io.quarkus.arc.impl.ComputingCache.computeIfAbsent(ComputingCache.java:69)
    at io.quarkus.arc.impl.AbstractSharedContext.get(AbstractSharedContext.java:26)
    at com.serrodcal.resource.EmployeeResource_RouteHandler_getEmployees_14d8a70f40a15f9fabb1eda0e5837c85c9f9dad2.invoke(EmployeeResource_RouteHandler_getEmployees_14d8a70f40a15f9fabb1eda0e5837c85c9f9dad2.zig:96)
    at io.quarkus.vertx.web.runtime.RouteHandler.handle(RouteHandler.java:53)
    at io.quarkus.vertx.web.runtime.RouteHandler.handle(RouteHandler.java:17)
    at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1036)
    at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:95)
    at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:132)
    at io.quarkus.vertx.http.runtime.VertxHttpRecorder$16.handle(VertxHttpRecorder.java:1096)
    at io.quarkus.vertx.http.runtime.VertxHttpRecorder$16.handle(VertxHttpRecorder.java:1067)
    at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1036)
    at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:131)
    at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:132)
    at io.quarkus.vertx.http.runtime.VertxHttpRecorder$4.handle(VertxHttpRecorder.java:322)
    at io.quarkus.vertx.http.runtime.VertxHttpRecorder$4.handle(VertxHttpRecorder.java:300)
    at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1036)
    at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:131)
    at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:132)
    at io.vertx.ext.web.impl.RouterImpl.handle(RouterImpl.java:54)
    at io.vertx.ext.web.impl.RouterImpl.handle(RouterImpl.java:36)
    at io.quarkus.vertx.http.runtime.VertxHttpRecorder$9.handle(VertxHttpRecorder.java:412)
    at io.quarkus.vertx.http.runtime.VertxHttpRecorder$9.handle(VertxHttpRecorder.java:409)
    at io.quarkus.vertx.http.runtime.VertxHttpRecorder$1.handle(VertxHttpRecorder.java:141)
    at io.quarkus.vertx.http.runtime.VertxHttpRecorder$1.handle(VertxHttpRecorder.java:126)
    at io.vertx.core.http.impl.WebSocketRequestHandler.handle(WebSocketRequestHandler.java:50)
    at io.vertx.core.http.impl.WebSocketRequestHandler.handle(WebSocketRequestHandler.java:32)
    at io.vertx.core.http.impl.Http1xServerConnection.handleMessage(Http1xServerConnection.java:136)
    at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:366)
    at io.vertx.core.impl.EventLoopContext.execute(EventLoopContext.java:43)
    at io.vertx.core.impl.ContextImpl.executeFromIO(ContextImpl.java:229)
    at io.vertx.core.net.impl.VertxHandler.channelRead(VertxHandler.java:163)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93)
    at io.netty.handler.codec.http.websocketx.extensions.WebSocketServerExtensionHandler.channelRead(WebSocketServerExtensionHandler.java:101)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.vertx.core.http.impl.Http1xUpgradeToH2CHandler.channelRead(Http1xUpgradeToH2CHandler.java:109)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.vertx.core.http.impl.Http1xOrH2CHandler.end(Http1xOrH2CHandler.java:61)
    at io.vertx.core.http.impl.Http1xOrH2CHandler.channelRead(Http1xOrH2CHandler.java:38)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
    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.lang.Thread.run(Thread.java:834)
    at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:517)
    at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:192)
Caused by: java.lang.RuntimeException: Error injecting com.serrodcal.repository.EmployeeRepository com.serrodcal.service.EmployeeService.employeeRepository
    at com.serrodcal.service.EmployeeService_Bean.create(EmployeeService_Bean.zig:148)
    at com.serrodcal.service.EmployeeService_Bean.create(EmployeeService_Bean.zig:171)
    at io.quarkus.arc.impl.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:96)
    at io.quarkus.arc.impl.AbstractSharedContext.access$000(AbstractSharedContext.java:14)
    at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:29)
    at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:26)
    at io.quarkus.arc.impl.LazyValue.get(LazyValue.java:26)
    at io.quarkus.arc.impl.ComputingCache.computeIfAbsent(ComputingCache.java:69)
    at io.quarkus.arc.impl.AbstractSharedContext.get(AbstractSharedContext.java:26)
    at com.serrodcal.service.EmployeeService_Bean.get(EmployeeService_Bean.zig:203)
    at com.serrodcal.service.EmployeeService_Bean.get(EmployeeService_Bean.zig:219)
    at com.serrodcal.resource.EmployeeResource_Bean.create(EmployeeResource_Bean.zig:131)
    ... 82 more
Caused by: java.lang.RuntimeException: Error injecting com.serrodcal.dao.EmployeeDao com.serrodcal.repository.EmployeeRepository.employeeDao
    at com.serrodcal.repository.EmployeeRepository_Bean.create(EmployeeRepository_Bean.zig:148)
    at com.serrodcal.repository.EmployeeRepository_Bean.create(EmployeeRepository_Bean.zig:171)
    at io.quarkus.arc.impl.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:96)
    at io.quarkus.arc.impl.AbstractSharedContext.access$000(AbstractSharedContext.java:14)
    at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:29)
    at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:26)
    at io.quarkus.arc.impl.LazyValue.get(LazyValue.java:26)
    at io.quarkus.arc.impl.ComputingCache.computeIfAbsent(ComputingCache.java:69)
    at io.quarkus.arc.impl.AbstractSharedContext.get(AbstractSharedContext.java:26)
    at com.serrodcal.repository.EmployeeRepository_Bean.get(EmployeeRepository_Bean.zig:203)
    at com.serrodcal.repository.EmployeeRepository_Bean.get(EmployeeRepository_Bean.zig:219)
    at com.serrodcal.service.EmployeeService_Bean.create(EmployeeService_Bean.zig:131)
    ... 93 more
Caused by: java.lang.IllegalStateException: The current thread cannot be blocked: vert.x-eventloop-thread-1
    at io.smallrye.mutiny.operators.UniBlockingAwait.await(UniBlockingAwait.java:29)
    at io.smallrye.mutiny.groups.UniAwait.atMost(UniAwait.java:61)
    at io.smallrye.mutiny.groups.UniAwait.indefinitely(UniAwait.java:42)
    at com.serrodcal.dao.EmployeeDao.initdb(EmployeeDao.java:37)
    at com.serrodcal.dao.EmployeeDao.config(EmployeeDao.java:28)
    at com.serrodcal.dao.EmployeeDao_Bean.create(EmployeeDao_Bean.zig:266)
    at com.serrodcal.dao.EmployeeDao_Bean.create(EmployeeDao_Bean.zig:282)
    at io.quarkus.arc.impl.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:96)
    at io.quarkus.arc.impl.AbstractSharedContext.access$000(AbstractSharedContext.java:14)
    at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:29)
    at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:26)
    at io.quarkus.arc.impl.LazyValue.get(LazyValue.java:26)
    at io.quarkus.arc.impl.ComputingCache.computeIfAbsent(ComputingCache.java:69)
    at io.quarkus.arc.impl.AbstractSharedContext.get(AbstractSharedContext.java:26)
    at com.serrodcal.dao.EmployeeDao_Bean.get(EmployeeDao_Bean.zig:314)
    at com.serrodcal.dao.EmployeeDao_Bean.get(EmployeeDao_Bean.zig:330)
    at com.serrodcal.repository.EmployeeRepository_Bean.create(EmployeeRepository_Bean.zig:131)
    ... 104 more

The beans are annotated as is given below:

@Singleton
public class EmployeeDao {
//...

Finally, they are injected with:

@Singleton
public class EmployeeRepository {

    @Inject
    EmployeeDao employeeDao;
//...

Expected behavior
The application should response to the request.

Actual behavior
After the application started fine, when I send a request I get a RuntimeException with the message "Error injecting com.serrodcal.dao.EmployeeDao com.serrodcal.repository.EmployeeRepository.employeeDao" for all the beans that they are Singleton.

To Reproduce

Go to this project: https://github.com/serrodcal/quarkus-architecture-istio/tree/main/quarkus-employee

Steps to reproduce the behavior:

  1. Go to quarkus-employee
  2. Compile the project: ./mvnw package -Pnative -Dquarkus.native.container-runtime=docker
  3. Build the docker image: docker build -f src/main/docker/Dockerfile.native -t quarkus/quarkus-employee-istio .
  4. Start a K8s cluster: kind create cluster
  5. Deploy the database: kubectl apply -f k8s/database.yaml
  6. Deploy the application: kubectl apply -f k8s/employee.yaml
  7. Expose the application: kubectl port-forward -n employee <pod>
  8. Call the application: curl localhost:8080/api/v1/employee
  9. Get the logs: kubectl logs -f -n employee <pod>

Configuration

quarkus.datasource.db-kind=postgresql
quarkus.datasource.username=quarkus_test
quarkus.datasource.password=quarkus_test
quarkus.datasource.reactive.url=postgresql://localhost:5432/quarkus_test
myapp.schema.create=true
quarkus.datasource.reactive.max-size=500

Screenshots

Environment (please complete the following information):

  • Output of uname -a or ver: Darwin MacBook-Pro-de-Sergio-2.local 20.1.0 Darwin Kernel Version 20.1.0: Sat Oct 31 00:07:11 PDT 2020; root:xnu-7195.50.7~2/RELEASE_X86_64 x86_64
  • Output of java -version:
OpenJDK Runtime Environment GraalVM CE 20.3.0 (build 11.0.9+10-jvmci-20.3-b06)
OpenJDK 64-Bit Server VM GraalVM CE 20.3.0 (build 11.0.9+10-jvmci-20.3-b06, mixed mode, sharing)
  • GraalVM version (if different from Java):
  • Quarkus version or git rev: 1.10.2.Final
  • Build tool (ie. output of mvnw --version or gradlew --version):
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /Users/serrodcal/.m2/wrapper/dists/apache-maven-3.6.3-bin/1iopthnavndlasol9gbrbg6bf2/apache-maven-3.6.3
Java version: 11.0.9, vendor: GraalVM Community, runtime: /Library/Java/JavaVirtualMachines/graalvm-ce-java11-20.3.0/Contents/Home
Default locale: es_ES, platform encoding: UTF-8
OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"

Additional context
The version of GraalVM within Docker container is 20.2.0 according to the information provided in Maven output in compiling time.

arepersistence kinquestion

Most helpful comment

Caused by: java.lang.IllegalStateException: The current thread cannot be blocked: vert.x-eventloop-thread-1

From the log above it, I'd say this is not something in relation to the bean scope but an operation that blocks the main event loop.

at io.smallrye.mutiny.operators.UniBlockingAwait.await(UniBlockingAwait.java:29)
    at io.smallrye.mutiny.groups.UniAwait.atMost(UniAwait.java:61)
    at io.smallrye.mutiny.groups.UniAwait.indefinitely(UniAwait.java:42)
    at com.serrodcal.dao.EmployeeDao.initdb(EmployeeDao.java:38)
    at com.serrodcal.dao.EmployeeDao.config(EmployeeDao.java:29)

What sort of init operation are you running on your EmployeeDao?
/cc @cescoffier @mkouba for additional insights.

Yes, that's correct. I forgot I have an await in EmployeeDao. The init method just populate the database when the bean is created:

@serrodcal FYI: If you are populating the database, using a migration extension Flyway or Liquibase will be suitable for the job.

All 9 comments

/cc @aguibert

Same behavior in native on the local maching (avoiding Docker). Reproduce the bug as is given below:

  1. Compile the application: ./mvnw clean package
  2. Start Postgresql using Docker: docker run --ulimit memlock=-1:-1 -it --rm=true --memory-swappiness=0 --name quarkus_test -e POSTGRES_USER=quarkus_test -e POSTGRES_PASSWORD=quarkus_test -e POSTGRES_DB=quarkus_test -p 5432:5432 postgres:10.5
  3. Start the application: ./target/quarkus-employee-istio-1.0.0-runner
  4. Send a request: curl localhost:8080/api/v1/employee -w "\n"

Finally, It also doesn't work using @ApplicationScoped for all the injections in Native, but the error is different:

2020-12-01 22:14:53,934 INFO  [io.quarkus] (main) quarkus-employee-istio 1.0.0 native (powered by Quarkus 1.10.2.Final) started in 0.024s. Listening on: http://0.0.0.0:8080
2020-12-01 22:14:53,934 INFO  [io.quarkus] (main) Profile prod activated. 
2020-12-01 22:14:53,934 INFO  [io.quarkus] (main) Installed features: [cdi, mutiny, reactive-pg-client, smallrye-context-propagation, smallrye-health, vertx, vertx-web]
2020-12-01 22:15:50,453 INFO  [com.ser.res.EmployeeResource] (vert.x-eventloop-thread-0) getEmployees
2020-12-01 22:15:50,453 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (vert.x-eventloop-thread-0) HTTP Request to /api/v1/employee failed, error id: 43cbc76f-c96d-4050-8b95-c770860d7dff-1: java.lang.IllegalStateException: The current thread cannot be blocked: vert.x-eventloop-thread-0
    at io.smallrye.mutiny.operators.UniBlockingAwait.await(UniBlockingAwait.java:29)
    at io.smallrye.mutiny.groups.UniAwait.atMost(UniAwait.java:61)
    at io.smallrye.mutiny.groups.UniAwait.indefinitely(UniAwait.java:42)
    at com.serrodcal.dao.EmployeeDao.initdb(EmployeeDao.java:38)
    at com.serrodcal.dao.EmployeeDao.config(EmployeeDao.java:29)
    at com.serrodcal.dao.EmployeeDao_Bean.create(EmployeeDao_Bean.zig:302)
    at com.serrodcal.dao.EmployeeDao_Bean.create(EmployeeDao_Bean.zig:318)
    at io.quarkus.arc.impl.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:96)
    at io.quarkus.arc.impl.AbstractSharedContext.access$000(AbstractSharedContext.java:14)
    at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:29)
    at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:26)
    at io.quarkus.arc.impl.LazyValue.get(LazyValue.java:26)
    at io.quarkus.arc.impl.ComputingCache.computeIfAbsent(ComputingCache.java:69)
    at io.quarkus.arc.impl.AbstractSharedContext.get(AbstractSharedContext.java:26)
    at io.quarkus.arc.impl.ClientProxies.getApplicationScopedDelegate(ClientProxies.java:17)
    at com.serrodcal.dao.EmployeeDao_ClientProxy.arc$delegate(EmployeeDao_ClientProxy.zig:67)
    at com.serrodcal.dao.EmployeeDao_ClientProxy.findAll(EmployeeDao_ClientProxy.zig:187)
    at com.serrodcal.repository.EmployeeRepository.getEmployees(EmployeeRepository.java:19)
    at com.serrodcal.repository.EmployeeRepository_ClientProxy.getEmployees(EmployeeRepository_ClientProxy.zig:217)
    at com.serrodcal.service.EmployeeService.getEmployees(EmployeeService.java:18)
    at com.serrodcal.service.EmployeeService_ClientProxy.getEmployees(EmployeeService_ClientProxy.zig:186)
    at com.serrodcal.resource.EmployeeResource.getEmployees(EmployeeResource.java:36)
    at com.serrodcal.resource.EmployeeResource_RouteHandler_getEmployees_14d8a70f40a15f9fabb1eda0e5837c85c9f9dad2.invoke(EmployeeResource_RouteHandler_getEmployees_14d8a70f40a15f9fabb1eda0e5837c85c9f9dad2.zig:115)
    at io.quarkus.vertx.web.runtime.RouteHandler.handle(RouteHandler.java:53)
    at io.quarkus.vertx.web.runtime.RouteHandler.handle(RouteHandler.java:17)
    at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1036)
    at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:95)
    at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:132)
    at io.quarkus.vertx.http.runtime.VertxHttpRecorder$16.handle(VertxHttpRecorder.java:1096)
    at io.quarkus.vertx.http.runtime.VertxHttpRecorder$16.handle(VertxHttpRecorder.java:1067)
    at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1036)
    at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:131)
    at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:132)
    at io.quarkus.vertx.http.runtime.VertxHttpRecorder$4.handle(VertxHttpRecorder.java:322)
    at io.quarkus.vertx.http.runtime.VertxHttpRecorder$4.handle(VertxHttpRecorder.java:300)
    at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1036)
    at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:131)
    at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:132)
    at io.vertx.ext.web.impl.RouterImpl.handle(RouterImpl.java:54)
    at io.vertx.ext.web.impl.RouterImpl.handle(RouterImpl.java:36)
    at io.quarkus.vertx.http.runtime.VertxHttpRecorder$9.handle(VertxHttpRecorder.java:412)
    at io.quarkus.vertx.http.runtime.VertxHttpRecorder$9.handle(VertxHttpRecorder.java:409)
    at io.quarkus.vertx.http.runtime.VertxHttpRecorder$1.handle(VertxHttpRecorder.java:141)
    at io.quarkus.vertx.http.runtime.VertxHttpRecorder$1.handle(VertxHttpRecorder.java:126)
    at io.vertx.core.http.impl.WebSocketRequestHandler.handle(WebSocketRequestHandler.java:50)
    at io.vertx.core.http.impl.WebSocketRequestHandler.handle(WebSocketRequestHandler.java:32)
    at io.vertx.core.http.impl.Http1xServerConnection.handleMessage(Http1xServerConnection.java:136)
    at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:366)
    at io.vertx.core.impl.EventLoopContext.execute(EventLoopContext.java:43)
    at io.vertx.core.impl.ContextImpl.executeFromIO(ContextImpl.java:229)
    at io.vertx.core.net.impl.VertxHandler.channelRead(VertxHandler.java:163)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93)
    at io.netty.handler.codec.http.websocketx.extensions.WebSocketServerExtensionHandler.channelRead(WebSocketServerExtensionHandler.java:101)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.vertx.core.http.impl.Http1xUpgradeToH2CHandler.channelRead(Http1xUpgradeToH2CHandler.java:109)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.vertx.core.http.impl.Http1xOrH2CHandler.end(Http1xOrH2CHandler.java:61)
    at io.vertx.core.http.impl.Http1xOrH2CHandler.channelRead(Http1xOrH2CHandler.java:38)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
    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.lang.Thread.run(Thread.java:834)
    at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:519)
    at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:192)

Caused by: java.lang.IllegalStateException: The current thread cannot be blocked: vert.x-eventloop-thread-1

From the log above it, I'd say this is not something in relation to the bean scope but an operation that blocks the main event loop.

at io.smallrye.mutiny.operators.UniBlockingAwait.await(UniBlockingAwait.java:29)
    at io.smallrye.mutiny.groups.UniAwait.atMost(UniAwait.java:61)
    at io.smallrye.mutiny.groups.UniAwait.indefinitely(UniAwait.java:42)
    at com.serrodcal.dao.EmployeeDao.initdb(EmployeeDao.java:38)
    at com.serrodcal.dao.EmployeeDao.config(EmployeeDao.java:29)

What sort of init operation are you running on your EmployeeDao?

/cc @cescoffier @mkouba for additional insights.

Caused by: java.lang.IllegalStateException: The current thread cannot be blocked: vert.x-eventloop-thread-1

From the log above it, I'd say this is not something in relation to the bean scope but an operation that blocks the main event loop.

at io.smallrye.mutiny.operators.UniBlockingAwait.await(UniBlockingAwait.java:29)
  at io.smallrye.mutiny.groups.UniAwait.atMost(UniAwait.java:61)
  at io.smallrye.mutiny.groups.UniAwait.indefinitely(UniAwait.java:42)
  at com.serrodcal.dao.EmployeeDao.initdb(EmployeeDao.java:38)
  at com.serrodcal.dao.EmployeeDao.config(EmployeeDao.java:29)

What sort of init operation are you running on your EmployeeDao?

/cc @cescoffier @mkouba for additional insights.

Yes, that's correct. I forgot I have an await in EmployeeDao. The init method just populate the database when the bean is created:

@Singleton
public class EmployeeDao {

    private io.vertx.mutiny.pgclient.PgPool client;

    @Inject
    @ConfigProperty(name = "myapp.schema.create", defaultValue = "true")
    boolean schemaCreate;

    @PostConstruct
    void config() {
        if (schemaCreate) {
            initdb();
        }
    }

    private void initdb() {
        client.query("DROP TABLE IF EXISTS employees").execute()
                .flatMap(r -> client.query("CREATE TABLE employees (id SERIAL PRIMARY KEY, name TEXT NOT NULL, dept_id BIGINT)").execute())
                .flatMap(r -> client.query("INSERT INTO employees (name) VALUES ('Lechowsky')").execute())
                .flatMap(r -> client.query("INSERT INTO employees (name) VALUES ('Serrodcal')").execute())
                .await().indefinitely();
    }

    EmployeeDao (io.vertx.mutiny.pgclient.PgPool client) {
        this.client = client;
    }

// ...

In previous versions I didn't get any error. Anyway, this example come from the Quarkus documentation.

The problem is that you can't block inside a @PostConstruct callback of a bean that is injected in a bean that declares a reactive route. You would have to mark the route as blocking (e.g. via @Route(type = HandlerType.BLOCKING)). Becaue normally when a route is invoked we assume it's non-blocking, i.e. invoked on the event loop thread.

I'd recommend you to initialize the DB eagerly, when the app starts, i.e. annotate EmployeeDao with @io.quarkus.runtime.Startup.

Just annotating the EmployeeDao bean with @Startup it works fine. Even using @Singleton.

Thanks a lot for your help. So, I think we can close this issue.

Caused by: java.lang.IllegalStateException: The current thread cannot be blocked: vert.x-eventloop-thread-1

From the log above it, I'd say this is not something in relation to the bean scope but an operation that blocks the main event loop.

at io.smallrye.mutiny.operators.UniBlockingAwait.await(UniBlockingAwait.java:29)
    at io.smallrye.mutiny.groups.UniAwait.atMost(UniAwait.java:61)
    at io.smallrye.mutiny.groups.UniAwait.indefinitely(UniAwait.java:42)
    at com.serrodcal.dao.EmployeeDao.initdb(EmployeeDao.java:38)
    at com.serrodcal.dao.EmployeeDao.config(EmployeeDao.java:29)

What sort of init operation are you running on your EmployeeDao?
/cc @cescoffier @mkouba for additional insights.

Yes, that's correct. I forgot I have an await in EmployeeDao. The init method just populate the database when the bean is created:

@serrodcal FYI: If you are populating the database, using a migration extension Flyway or Liquibase will be suitable for the job.

Caused by: java.lang.IllegalStateException: The current thread cannot be blocked: vert.x-eventloop-thread-1

From the log above it, I'd say this is not something in relation to the bean scope but an operation that blocks the main event loop.

at io.smallrye.mutiny.operators.UniBlockingAwait.await(UniBlockingAwait.java:29)
  at io.smallrye.mutiny.groups.UniAwait.atMost(UniAwait.java:61)
  at io.smallrye.mutiny.groups.UniAwait.indefinitely(UniAwait.java:42)
  at com.serrodcal.dao.EmployeeDao.initdb(EmployeeDao.java:38)
  at com.serrodcal.dao.EmployeeDao.config(EmployeeDao.java:29)

What sort of init operation are you running on your EmployeeDao?
/cc @cescoffier @mkouba for additional insights.

Yes, that's correct. I forgot I have an await in EmployeeDao. The init method just populate the database when the bean is created:

@serrodcal FYI: If you are populating the database, using a migration extension Flyway or Liquibase will be suitable for the job.

@machi1990 thanks for the recommendation. I knew those tools are available but, personally, I don't like to use them because the application will be coupled to the database. Anyway, this project is just for learning.

Was this page helpful?
0 / 5 - 0 ratings