RequestScope not active in Retry when using a Qualifier
See original GitHub issueEnvironment Details
- Helidon Version: 2.1.0
- Helidon MP
- JDK version: 11.0.6+8-LTS
- OS: OSX 10.15.6
Problem Description
When using Helidon MP Fault Tolerance Retry with a Request Scope bean where there is a custom Qualifier in scope getting a Weld Exception “WELD-001303: No active contexts for scope type javax.enterprise.context.RequestScoped” Can see the retries are happening but if the last Retry fails the WELD Exception is returned and the underlying error is suppressed.
Full stack trace:
java.lang.Exception: No tenant context.
at test.RequestTestQualifier.test(RequestTestQualifier.java:58)
at test.RequestTestQualifier$Proxy$_$$_WeldClientProxy.test(Unknown Source)
at test.SomeService.test(SomeService.java:61)
at test.SomeService$Proxy$_$$_WeldSubclass.test$$super(Unknown Source)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.jboss.weld.interceptor.proxy.TerminalAroundInvokeInvocationContext.proceedInternal(TerminalAroundInvokeInvocationContext.java:51)
at org.jboss.weld.interceptor.proxy.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:78)
at io.helidon.microprofile.faulttolerance.MethodInvoker.lambda$toCompletionStageSupplier$19(MethodInvoker.java:637)
at io.helidon.faulttolerance.DelayedTask$2.execute(DelayedTask.java:114)
at io.helidon.faulttolerance.RetryImpl.retrySingle(RetryImpl.java:92)
at io.helidon.faulttolerance.RetryImpl.lambda$retrySingle$0(RetryImpl.java:104)
at io.helidon.common.reactive.SingleOnErrorResumeWith$OnErrorResumeWithSubscriber.onError(SingleOnErrorResumeWith.java:82)
at io.helidon.common.reactive.DeferredScalarSubscription.error(DeferredScalarSubscription.java:132)
at io.helidon.common.reactive.MultiFromCompletionStage$CompletionStageSubscription.accept(MultiFromCompletionStage.java:70)
at io.helidon.common.reactive.MultiFromCompletionStage$CompletionStageSubscription.accept(MultiFromCompletionStage.java:52)
at io.helidon.common.reactive.MultiFromCompletionStage$AtomicBiConsumer.accept(MultiFromCompletionStage.java:95)
at io.helidon.common.reactive.MultiFromCompletionStage$AtomicBiConsumer.accept(MultiFromCompletionStage.java:88)
at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:859)
at java.base/java.util.concurrent.CompletableFuture.uniWhenCompleteStage(CompletableFuture.java:883)
at java.base/java.util.concurrent.CompletableFuture.whenComplete(CompletableFuture.java:2251)
at java.base/java.util.concurrent.CompletableFuture.whenComplete(CompletableFuture.java:143)
at io.helidon.common.reactive.MultiFromCompletionStage.subscribe(MultiFromCompletionStage.java:49)
at io.helidon.common.reactive.SingleFromCompletionStage.subscribe(SingleFromCompletionStage.java:38)
at io.helidon.common.reactive.SingleOnErrorResumeWith.subscribe(SingleOnErrorResumeWith.java:43)
at io.helidon.common.reactive.SingleOnErrorResumeWith$OnErrorResumeWithSubscriber.onError(SingleOnErrorResumeWith.java:92)
at io.helidon.common.reactive.DeferredScalarSubscription.error(DeferredScalarSubscription.java:132)
at io.helidon.common.reactive.MultiFromCompletionStage$CompletionStageSubscription.accept(MultiFromCompletionStage.java:70)
at io.helidon.common.reactive.MultiFromCompletionStage$CompletionStageSubscription.accept(MultiFromCompletionStage.java:52)
at io.helidon.common.reactive.MultiFromCompletionStage$AtomicBiConsumer.accept(MultiFromCompletionStage.java:95)
at io.helidon.common.reactive.MultiFromCompletionStage$AtomicBiConsumer.accept(MultiFromCompletionStage.java:88)
at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:859)
at java.base/java.util.concurrent.CompletableFuture.uniWhenCompleteStage(CompletableFuture.java:883)
at java.base/java.util.concurrent.CompletableFuture.whenComplete(CompletableFuture.java:2251)
at java.base/java.util.concurrent.CompletableFuture.whenComplete(CompletableFuture.java:143)
at io.helidon.common.reactive.MultiFromCompletionStage.subscribe(MultiFromCompletionStage.java:49)
at io.helidon.common.reactive.SingleFromCompletionStage.subscribe(SingleFromCompletionStage.java:38)
at io.helidon.common.reactive.SingleOnErrorResumeWith.subscribe(SingleOnErrorResumeWith.java:43)
at io.helidon.common.reactive.SingleOnErrorResumeWith$OnErrorResumeWithSubscriber.onError(SingleOnErrorResumeWith.java:92)
at io.helidon.common.reactive.DeferredScalarSubscription.error(DeferredScalarSubscription.java:132)
at io.helidon.common.reactive.MultiFromCompletionStage$CompletionStageSubscription.accept(MultiFromCompletionStage.java:70)
at io.helidon.common.reactive.MultiFromCompletionStage$CompletionStageSubscription.accept(MultiFromCompletionStage.java:52)
at io.helidon.common.reactive.MultiFromCompletionStage$AtomicBiConsumer.accept(MultiFromCompletionStage.java:95)
at io.helidon.common.reactive.MultiFromCompletionStage$AtomicBiConsumer.accept(MultiFromCompletionStage.java:88)
at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:859)
at java.base/java.util.concurrent.CompletableFuture.uniWhenCompleteStage(CompletableFuture.java:883)
at java.base/java.util.concurrent.CompletableFuture.whenComplete(CompletableFuture.java:2251)
at java.base/java.util.concurrent.CompletableFuture.whenComplete(CompletableFuture.java:143)
at io.helidon.common.reactive.MultiFromCompletionStage.subscribe(MultiFromCompletionStage.java:49)
at io.helidon.common.reactive.SingleFromCompletionStage.subscribe(SingleFromCompletionStage.java:38)
at io.helidon.common.reactive.SingleOnErrorResumeWith.subscribe(SingleOnErrorResumeWith.java:43)
at io.helidon.common.reactive.CompletionSingle.toNullableStage(CompletionSingle.java:40)
at io.helidon.common.LazyValueImpl.get(LazyValueImpl.java:58)
at io.helidon.common.reactive.CompletionAwaitable.whenComplete(CompletionAwaitable.java:274)
at io.helidon.common.reactive.CompletionAwaitable.whenComplete(CompletionAwaitable.java:33)
at io.helidon.common.reactive.MultiFromCompletionStage.subscribe(MultiFromCompletionStage.java:49)
at io.helidon.common.reactive.SingleFromCompletionStage.subscribe(SingleFromCompletionStage.java:38)
at io.helidon.common.reactive.Single.toStage(Single.java:666)
at io.helidon.microprofile.faulttolerance.MethodInvoker.get(MethodInvoker.java:436)
at io.helidon.microprofile.faulttolerance.CommandInterceptor.interceptCommand(CommandInterceptor.java:54)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.jboss.weld.interceptor.reader.SimpleInterceptorInvocation$SimpleMethodInvocation.invoke(SimpleInterceptorInvocation.java:73)
at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.executeAroundInvoke(InterceptorMethodHandler.java:84)
at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.executeInterception(InterceptorMethodHandler.java:72)
at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.invoke(InterceptorMethodHandler.java:56)
at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:79)
at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:68)
at test.SomeService$Proxy$_$$_WeldSubclass.test(Unknown Source)
at test.SomeService$Proxy$_$$_WeldClientProxy.test(Unknown Source)
at test.MultiTenantService.getTenantResource(MultiTenantService.java:66)
at test.MultiTenantService$Proxy$_$$_WeldSubclass.getTenantResource$$super(Unknown Source)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.jboss.weld.interceptor.proxy.TerminalAroundInvokeInvocationContext.proceedInternal(TerminalAroundInvokeInvocationContext.java:51)
at org.jboss.weld.interceptor.proxy.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:78)
at io.helidon.metrics.HelidonSimpleTimer$SimpleTimerImpl.time(HelidonSimpleTimer.java:184)
at io.helidon.metrics.HelidonSimpleTimer.time(HelidonSimpleTimer.java:64)
at io.helidon.microprofile.metrics.InterceptorSyntheticSimplyTimed.interceptRestEndpoint(InterceptorSyntheticSimplyTimed.java:72)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.jboss.weld.interceptor.reader.SimpleInterceptorInvocation$SimpleMethodInvocation.invoke(SimpleInterceptorInvocation.java:73)
at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.executeAroundInvoke(InterceptorMethodHandler.java:84)
at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.executeInterception(InterceptorMethodHandler.java:72)
at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.invoke(InterceptorMethodHandler.java:56)
at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:79)
at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:68)
at test.MultiTenantService$Proxy$_$$_WeldSubclass.getTenantResource(Unknown Source)
at test.MultiTenantService$Proxy$_$$_WeldClientProxy.getTenantResource(Unknown Source)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:52)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:124)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:167)
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:219)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:79)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:469)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:391)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:80)
at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:255)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:244)
at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
at org.glassfish.jersey.internal.Errors.process(Errors.java:244)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:265)
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:234)
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:680)
at io.helidon.webserver.jersey.JerseySupport$JerseyHandler.lambda$doAccept$3(JerseySupport.java:265)
at io.helidon.common.context.Contexts.runInContext(Contexts.java:98)
at io.helidon.common.context.ContextAwareExecutorImpl.lambda$wrap$1(ContextAwareExecutorImpl.java:129)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Suppressed: java.lang.Exception: No tenant context.
at test.RequestTestQualifier.test(RequestTestQualifier.java:58)
at test.RequestTestQualifier$Proxy$_$$_WeldClientProxy.test(Unknown Source)
at test.SomeService.test(SomeService.java:61)
at test.SomeService$Proxy$_$$_WeldSubclass.test$$super(Unknown Source)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.jboss.weld.interceptor.proxy.TerminalAroundInvokeInvocationContext.proceedInternal(TerminalAroundInvokeInvocationContext.java:51)
at org.jboss.weld.interceptor.proxy.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:78)
at io.helidon.microprofile.faulttolerance.MethodInvoker.lambda$toCompletionStageSupplier$19(MethodInvoker.java:637)
at io.helidon.faulttolerance.DelayedTask$2.execute(DelayedTask.java:114)
at io.helidon.faulttolerance.RetryImpl.retrySingle(RetryImpl.java:92)
at io.helidon.faulttolerance.RetryImpl.invoke(RetryImpl.java:63)
at io.helidon.faulttolerance.FaultTolerance$TypedBuilder$TypedWrapper.invoke(FaultTolerance.java:302)
at io.helidon.faulttolerance.FaultTolerance$TypedBuilder$FtHandlerTypedImpl.lambda$invoke$1(FaultTolerance.java:276)
at io.helidon.faulttolerance.FaultTolerance$TypedBuilder$FtHandlerTypedImpl.invoke(FaultTolerance.java:279)
at io.helidon.microprofile.faulttolerance.MethodInvoker.lambda$get$7(MethodInvoker.java:383)
at io.helidon.common.context.Contexts.runInContextWithThrow(Contexts.java:142)
at io.helidon.microprofile.faulttolerance.MethodInvoker.lambda$get$8(MethodInvoker.java:382)
at io.helidon.microprofile.faulttolerance.MethodInvoker.get(MethodInvoker.java:435)
... 63 more
Suppressed: java.lang.Exception: No tenant context.
at test.RequestTestQualifier.test(RequestTestQualifier.java:58)
at test.RequestTestQualifier$Proxy$_$$_WeldClientProxy.test(Unknown Source)
at test.SomeService.test(SomeService.java:61)
at test.SomeService$Proxy$_$$_WeldSubclass.test$$super(Unknown Source)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.jboss.weld.interceptor.proxy.TerminalAroundInvokeInvocationContext.proceedInternal(TerminalAroundInvokeInvocationContext.java:51)
at org.jboss.weld.interceptor.proxy.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:78)
at io.helidon.microprofile.faulttolerance.MethodInvoker.lambda$toCompletionStageSupplier$19(MethodInvoker.java:637)
at io.helidon.faulttolerance.DelayedTask$2.execute(DelayedTask.java:114)
at io.helidon.faulttolerance.RetryImpl.retrySingle(RetryImpl.java:92)
at io.helidon.faulttolerance.RetryImpl.lambda$retrySingle$0(RetryImpl.java:104)
at io.helidon.common.reactive.SingleOnErrorResumeWith$OnErrorResumeWithSubscriber.onError(SingleOnErrorResumeWith.java:82)
... 83 more
Suppressed: java.lang.Exception: No tenant context.
at test.RequestTestQualifier.test(RequestTestQualifier.java:58)
at test.RequestTestQualifier$Proxy$_$$_WeldClientProxy.test(Unknown Source)
at test.SomeService.test(SomeService.java:61)
at test.SomeService$Proxy$_$$_WeldSubclass.test$$super(Unknown Source)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.jboss.weld.interceptor.proxy.TerminalAroundInvokeInvocationContext.proceedInternal(TerminalAroundInvokeInvocationContext.java:51)
at org.jboss.weld.interceptor.proxy.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:78)
at io.helidon.microprofile.faulttolerance.MethodInvoker.lambda$toCompletionStageSupplier$19(MethodInvoker.java:637)
at io.helidon.faulttolerance.DelayedTask$2.execute(DelayedTask.java:114)
at io.helidon.faulttolerance.RetryImpl.retrySingle(RetryImpl.java:92)
at io.helidon.faulttolerance.RetryImpl.lambda$retrySingle$0(RetryImpl.java:104)
at io.helidon.common.reactive.SingleOnErrorResumeWith$OnErrorResumeWithSubscriber.onError(SingleOnErrorResumeWith.java:82)
... 96 more
Steps to reproduce
Qualifer:
@Qualifier
@Retention(RUNTIME)
@Target({TYPE, METHOD, FIELD, PARAMETER})
public @interface TestQualifier {
}
Qualifier usage:
@RequestScoped
@TestQualifier
public class RequestTestQualifier {
@Inject
TenantContext tenantContext;
public String test() throws Exception {
String tenantId = tenantContext.getTenantId();
System.out.println("Tenant Context: "+tenantId);
if (tenantId == null) {
throw new Exception("No tenant context.");
}
return tenantId;
}
}
Request Scoped Bean
@RequestScoped
public class TenantContext {
@Context
private ServerRequest mRequest;
public String getTenantId() {
return mRequest.headers().value("x-tenant-id").orElse(null);
}
}
Service with Retry:
@ApplicationScoped
public class SomeService {
@Inject
@TestQualifier
RequestTestQualifier requestTestQualifier;
@Retry
public String test() throws Exception {
return requestTestQualifier.test();
}
}
Resource:
@RequestScoped
public class MultiTenantService {
@Inject
SomeService someService;
@GET
public String getTenantResource() {
try {
return someService.test();
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
}
Call endpoint GET /test without a header to get exception:
curl http://localhost:8080/test
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
RequestScope not active in Retry when using a Qualifier #2480
Can see the retries are happening but if the last Retry fails the WELD Exception is returned and the underlying error is suppressed....
Read more >Why does Spring reject @Qualifier for a request-scoped bean ...
However, Spring rejects the qualifier completely, behaving as if there was no suitable @Component around. For example, the following test fails ...
Read more >Core Technologies - Spring
When using annotation-driven components or Java configuration, the @RequestScope annotation can be used to assign a component to the request scope.
Read more >CDI Managed Beans as JMS listeners (Version 1) - jms-spec
This means that if the JMS listener bean observes events with the qualifier, say, @Initialized(RequestScoped.class) then an instance of the bean will be...
Read more >Table of Contents - Micronaut Documentation
Historically, frameworks such as Spring and Grails were not designed to run in ... you can build your own qualifiers using the Qualifier...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@spericas I tested the 2.1.1-SNAPSHOT for my test example and for our application and the issue is not happening with the custom qualifier. The fix looks good. Many thanks!
@bunto76 It is now hopefully fixed by PR #2495. If at all possible for you to try out the fix before our next release, it would be great.