Describe the bug
I get a ContextNotActiveException when I put a CacheResult annotation on a method and make the first call (not hitting the cache). If i remove it, everything works fine.
java.util.concurrent.CompletionException: javax.enterprise.context.ContextNotActiveException: interface javax.enterprise.context.RequestScoped
at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:273)
at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:280)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1592)
at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1582)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: javax.enterprise.context.ContextNotActiveException: interface javax.enterprise.context.RequestScoped
at io.quarkus.hibernate.orm.runtime.RequestScopedEntityManagerHolder_ClientProxy.arc$delegate(RequestScopedEntityManagerHolder_ClientProxy.zig:83)
at io.quarkus.hibernate.orm.runtime.RequestScopedEntityManagerHolder_ClientProxy.getOrCreateEntityManager(RequestScopedEntityManagerHolder_ClientProxy.zig:191)
at io.quarkus.hibernate.orm.runtime.entitymanager.TransactionScopedEntityManager.getEntityManager(TransactionScopedEntityManager.java:77)
at io.quarkus.hibernate.orm.runtime.entitymanager.TransactionScopedEntityManager.createQuery(TransactionScopedEntityManager.java:316)
at io.quarkus.hibernate.orm.runtime.entitymanager.ForwardingEntityManager.createQuery(ForwardingEntityManager.java:142)
at io.quarkus.hibernate.orm.panache.runtime.JpaOperations.find(JpaOperations.java:266)
at io.quarkus.hibernate.orm.panache.runtime.JpaOperations.find(JpaOperations.java:276)
at io.quarkus.hibernate.orm.panache.runtime.JpaOperations.find(JpaOperations.java:272)
at e.r.x.c.domain.repository.DomainClusterRepository.find(DomainClusterRepository.java)
at e.r.x.c.domain.repository.DomainClusterRepository.findByIdCodeAndIdDomainCode(DomainClusterRepository.java:15)
at e.r.x.c.domain.repository.DomainClusterRepository_ClientProxy.findByIdCodeAndIdDomainCode(DomainClusterRepository_ClientProxy.zig:1723)
at e.r.x.c.domain.service.impl.DomainService.getDomainCluster(DomainService.java:27)
at e.r.x.c.domain.service.impl.DomainService_ClientProxy.getDomainCluster(DomainService_ClientProxy.zig:166)
at e.r.x.c.service.impl.CodeConversorServiceImpl.getConvertedValue(CodeConversorServiceImpl.java:56)
at e.r.x.c.service.impl.CodeConversorServiceImpl_ClientProxy.getConvertedValue(CodeConversorServiceImpl_ClientProxy.zig:261)
at e.r.x.c.typecode.service.impl.TypeCodeService.findTypeCodeByNotNormalizedCode(TypeCodeService.java:94)
at e.r.x.c.typecode.service.impl.TypeCodeService_Subclass.findTypeCodeByNotNormalizedCode$$superaccessor1(TypeCodeService_Subclass.zig:277)
at e.r.x.c.typecode.service.impl.TypeCodeService_Subclass$$function$$5.apply(TypeCodeService_Subclass$$function$$5.zig:59)
at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
at io.quarkus.cache.runtime.CacheResultInterceptor.lambda$intercept$0(CacheResultInterceptor.java:27)
at io.quarkus.cache.runtime.caffeine.CaffeineCache$MappingSupplier.get(CaffeineCache.java:133)
at io.quarkus.cache.runtime.caffeine.CaffeineCache.lambda$get$0(CaffeineCache.java:55)
at com.github.benmanes.caffeine.cache.LocalAsyncCache.lambda$get$0(LocalAsyncCache.java:77)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590)
Expected behavior
Get result without exception. Value put in the cache. Cache hitted on second call
Actual behavior
ContextNotActiveException rised on first call (not hitting the cache. Just trying to get the value persisted in database)
To Reproduce
Configuration
# configure your datasource
quarkus.datasource.db-kind = postgresql
quarkus.datasource.username = x
quarkus.datasource.password = x
quarkus.datasource.jdbc.url = jdbc:postgresql://localhost:5432/x
quarkus.http.port=8081
# drop and create the database at startup (use `update` to only update the schema)
quarkus.hibernate-orm.database.generation = validate
#quarkus.hibernate-orm.database.generation = drop-and-create
quarkus.flyway.migrate-at-start= true
Screenshots
(If applicable, add screenshots to help explain your problem.)
Environment (please complete the following information):
Additional context
Nothing, I suppouse
Thanks a lot in advance
Same problem with the same version. Struggling with it since 3 hours, I had no idea it was due to the CacheResult annotation. I just commented it out and the error was gone.
I've just realised that it happens if and only if the panache is used. I have another microservice not using the panache but with the CacheResult annotation and it works fine.
Thanks for reporting this issue @daniel-alonso-sanchez and @dwamara!
I'm taking a look at it.
I could reproduce it easily. This is probably caused by the lack of context propagation in the cache extension.
I'm exploring solutions now.
Thanks for your support @gwenneg !!!
I get a null pointer exception when using @CacheResult in combination with jaeger. Could it be related?
Exception in thread "pool-3-thread-1" java.lang.NullPointerException
at io.quarkus.jaeger.runtime.MDCScope.<init>(MDCScope.java:25)
at io.quarkus.jaeger.runtime.MDCScopeManager.activate(MDCScopeManager.java:17)
at io.smallrye.opentracing.OpenTracingAsyncInterceptor.applyContext(OpenTracingAsyncInterceptor.java:37)
If I set quarkus.jaeger.enabled=false the caching works fine.
@guldner I don't see any obvious link betwen your Jaeger issue and this one. Could you please create a new GitHub issue and provide us with a minimal reproducer if possible? I'll take a look at it.
@gwenneg Sorry for the late reply.
Issue created: https://github.com/quarkusio/quarkus/issues/8483
Thanks
@daniel-alonso-sanchez: This issue should be fixed with Quarkus 1.5.0. You will need to add quarkus-smallrye-context-propagation to your project dependencies to enable the context propagation into the cache extension.
Ok!! Thanks a lot to you, @gwenneg and the rest of the team!
Hello to all. I am still experience this even after adding the dependency to quarkus-smallrye-context-propagation in Quarkus 1.4.1 . I tried RequestScoped and ApplicationScoped Beans and I get always the same exception Caused by: javax.enterprise.context.ContextNotActiveException: interface javax.enterprise.context.RequestScoped . So it is not enough to declare the dependency but we have to wait for Quarkus 1.5.0 ?
Yes @akoufa, you have to wait for Quarkus 1.5.0 to get this issue fixed.
Yes @akoufa, you have to wait for Quarkus
1.5.0to get this issue fixed.
that's a bummer. I had to comment out the annotation in a lot of places, I will have to track them all down when updating to 1.5.
Any release time/date in plan?