-
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
RestClient Reactive: Context not propagated #16949
Comments
This is an interesting use case. What happens is that when the rest client resumes execution (i.e. an HTTP client response is created), execution resumes on a Vert.x event loop thread instead of a worker pool thread (as is appropriate because in this case the endpoint is a RESTEasy Reactive endpoint using There are two things we can do:
I believe the second option is the best. |
I would also go for 2 until we have lots of demand for this use case. If you block the thread for the HTTP request (which makes sense you are on a worker thread anyway), it should work. If you REST client returns a Uni, use |
So first: this is not about context propagation, because I assume the context is properly propagated. If there was a This is purely about ORM refusing to work on a vert.x IO thread, which is a Good Thing™. What's peculiar in this use-case is that we're using I think we could document this, or perhaps improve the error message by telling users to use @geoand this sort of mistake we can detect in RR by catching the exception thrown by ORM and if we notice the endpoint was async (returned a Or we could add that |
We do return the thread to the pool, but my point is that doing this mixing and matching is very error prone and we should likely prevent it when we can.
To be honest, I don't think that mixing |
out of curiosity, would that work with |
@FroMage USing blocking calls is documented on the mutiny documentation: https://smallrye.io/smallrye-mutiny/guides/imperative-to-reactive. The problem is that after you dispatched the subscription (runSubscriptionOn) or the event (emitOn), you don't go back to the previous thread, which means we need to be sure that everything is captured and restored. |
Huh, that's interesting. I wonder if there's any legitimate use-case for allowing it. |
From what I have seen, users do that because either they don't understand what is going on under the hood or because they want to use some of the API that Uni provides |
If I can give my experience I use the reactive APIs with Blocking annotation because I'm still use blocking Hibernate waiting for the stability of the reactive one. This helps me with the migration as I wouldn't refactor the entire application |
But in that case why would you use coroutines? Why not just use blocking APIs for the entire request handling? |
Because I already have the reactive code in place |
Is that code actually non blocking though or does it just use reactive types? |
It's completely non blocking except Hibernate that is executed within a deferred Uni |
Personally I don't see the point in mixing that way, but I understand where you are coming from. The problem is it can lead to unexpected behavior. |
Can you show us your code? If Hibernate is executed in a deferred |
Hi this is the main repository class that I'm using right now |
Can you retry this with |
Closing this as there were some relevant fixes that have gone in. |
Describe the bug
Hi. I'm working with a blocking implentation of Hibernate using the @Blocking annotation. As is the software is operating with the database without issues. Adding a http request in the chain using Restclient reactive than I have the following message that probabily indicates that the context is not propagated even if quarkus-smallrye-context-propagation is added.
2021-05-03 15:10:07,939 ERROR [org.jbo.res.rea.com.cor.AbstractResteasyReactiveContext] (executor-thread-198) Request failed: java.lang.IllegalStateException: You have attempted to perform a blocking operation on a IO thread. This is not allowed, as blocking the IO thread will cause major performance issues with your application. If you want to perform blocking EntityManager operations make sure you are doing it from a worker thread.
To Reproduce
Here a small reproducer
demo.zip
Inside you have a working and a non working API
Output of
java -version
openjdk version "11.0.11" 2021-04-20
Quarkus version or git rev
Quarkus 1.13.3
The text was updated successfully, but these errors were encountered: