-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
ContextNotActiveException when using SuspendableContainerRequestContext #2981
Comments
You should use MP-CP. You can inject a I don't think we can use |
I see what you mean. So, as I understand it, I need to propagate the current context so that I can call Just two notes
|
Reactive Streams is not an implementation, it's an API. The implementation is either RxJava2 or Reactor. Do you know which one it is you're using?
If the Mongo client is using RS-Operators, then it uses RxJava2 and so yes, it should work. Is that the case? |
Thanks for the immediate answer. Actually, this is the driver I am using: It exposes APIs only through publishers and subscribers from the org.reactivestreams implementation. The other ones, like seem to be abandoned officially, as stated by the docs. |
OK, so you're right, they implemented their own RS implementation. That's ambitious. So in any case, MP-CP cannot propagate context automatically in this case since it does not know about their implementation. This should get you working: Executor contextExecutor = context.currentContextExecutor();
Subscriber<Document> subscriber = new Subscriber<Document>() {
@Override
public void onSubscribe(Subscription s) {
contextExecutor.execute(() -> s.request(1));
}
@Override
public void onNext(Document document) {
//this never gets called
}
@Override
public void onError(Throwable t) {
System.out.println("error: " + t.toString());
//TODO
}
@Override
public void onComplete() {
System.out.println("completed");
contextExecutor.execute(() -> suspendableContainerRequestContext.resume()); //CRASHES! Context Not Active?
}
}; With this thread context injected in your interceptor: @Inject
ThreadContext context; You can also use programmatic injection if your interceptor is not a bean. |
I've filed eclipse/microprofile-context-propagation#166 to add support for this to MP-CP. |
@FroMage thank you. But I still have no luck.
Error: The error seems to have changed a little, but the root of the problem is probably the same, am I right? |
I apologize. Your solution worked, and I thank you very much, @FroMage . The next error originated by somewhere else in my code, where I hadn't used MP-CP (where I also should). |
OK, excellent, this is great news :) Let me know if you have success in that other part of your code. |
@FroMage I stumbled across a discovery, actually. The other error was inside my interceptor, where I also wanted to do some logging of the inbound request. This is a method interceptor - so no filter there. It turns out that when using the method suggested, the HTTPServletRequest cannot be injected anymore. Sample code exhibiting the problem:
I have injected the HTTP Servlet Request via The request is also inactive inside the interceptor. So, I don't know why this is caused or how can I get the HTTPServletRequest from inside an interceptor (it worked while using sync filters). |
So, probably |
Maybe this has something to do with this problem? eclipse/microprofile-context-propagation#134 Is the current request being treated a different way? If yes, how can I gain access to the current request inside an interceptor when async filters are used in Quarkus? |
No, it's probably that we need a context provider for undertow. I just have to find what injects that servlet request. |
So what's your exact stack trace? |
It looks like |
Most probably you are right. Here is a capture of the stacktrace. The exception is caused by accessing the injected HTTPServletRequest inside an interceptor (medhod annotated with @AroundInvoke). The relevant piece of code inside the handler of @AroundInvoke:
The Stacktrace Capture: |
OK, I should have fixed it with #3006, can you try it out? |
@FroMage thank you very much. I will try it later today, since I need to setup my environment to compile quarkus, and use specific versions, etc. I will post back with my findings. |
OK thanks. |
@FroMage I can verify that your fork works. I build the entire Quarkus from source (your fork) and I added 999-SNAPSHOT as a dependency. I can see that HTTPServletRequest is usable again, after the asynchronous filter ends. Thank you very much for your support and your efforts. I will wait until this gets merged into an official release. |
Support CP for undertow servlet request #2981
OK, let's close this issue then, thanks! |
Hello, I recently had to make changes to the dependencies in my Quarkus project. I am now using both Resteasy Reactive and Resteasy Classic in different parts of the project. However, since the changes, I have been receiving the error message |
I am using Mongo (JVM, I do not care about native) as a pre-request filter, in order to get some data from the MongoDB before it reaches the actual Resource.
Mongo Driver is asynchronous by nature, so I call
suspend()
before I start making the call. However, when trying to doresume()
, I get ajavax.enterprise.context.ContextNotActiveException
.The following is written in the
public void filter(ContainerRequestContext requestContext)
function of aContainerRequestFilter
When the
onComplete()
is called, I get theContextNotActiveException
.The text was updated successfully, but these errors were encountered: