-
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
Error under load "Detected use of the reactive Session from a different Thread..." #23324
Comments
/cc @DavideD, @Sanne, @gavinking |
Thanks for the report! We'll have a look. I didn't check the details but I suspect it might relate to #23300 - let's fix that one first, then verify. |
I am facing exact same issue when load testing my quarkus application. My application is very similar to this quickstart project - https://github.com/quarkusio/quarkus-quickstarts/tree/main/hibernate-reactive-panache-quickstart. Is there any workaround until #23300 is fixed? |
I've described the "workaround" for that issue on it: |
I was running into this problem again, but it seems that it is working at some places, and at others it is not. workaround: instead of
using this
The workaround really helps, but is there any progress with this issue so far already @Sanne ? |
hi @mklueh in that particular case I suspect you're hitting a very similar issue (but not the same) with scopes in reactive messaging. This should be fixed in Quarkus 2.7.2 - could you try it? |
Hello @Sanne with the quarkus 2.7.5 Final we still facing this issue under load. Especially directly after quarkus startup. Without high load it works fine. |
Is there any update on this topic? Do I have to wrap every method that operates on the database with Panache. WithTransaction? Reactive Hibernate is not stable, and often causes errors.The quarkus version I use is 2.8.2.final. |
Let me explain, Hibernate Reactive by design requires all operations to be executed from the same thread. The exception "java.lang.IllegalStateException: HR000069: Detected use of the reactive Session from a different Thread than ..." literally means that we've detected illegal use of it, and we're throwing an exception on purpose so that integration problems can be detected (such integration problems would otherwise most likely lead to more serious issues, such as data inconsistencies being written). If you have such issues, you're using it in the wrong context. If you can't strictly guarantee that your application is fully reactive and that each transaction is constrained within the same unique thread, you shouldn't use it; consider using Hiberante ORM blocking, which is more suited for non-blocking designs. The reason Also, please use the
Well as I mentioned we throw these exceptions on purpose - not because it's unstable but most likely because it's not being used correctly. I'll have another look at the reproducer of this issue - pretty sure something is wrong in the integration. Other people commenting here... please open a different issue and attach a reproducer, I can't help you otherwise - sorry :/ |
I've tested the original testcase with Quarkus 2.9.2 and I cannot see the error anymore. Still, I'm not sure how one is supposed to implement this use-case. This is what the test case is trying to achieve:
Point 4 is implemented this way:
Is this the right approach to use? When I've upgraded to Quarkus 2.9.2 I had to add
I'm asking because it doesn't seem to work and I get the error
I think the error the issue is referring to has been solved but it would be nice to fix the testcase so that it works |
"workaround" you can try:
|
I'm not sure that's the right approach. I think a better solution would is to use the Hibernate Session factory directly. But I need to test it. |
If I use the Hibernate Reactive session factory, I see this error:
|
This implementation should work though:
|
Hi. I am facing the same issue. I am currently using 2.16.5.Final. in new versions is this solved? or I have to go with some kind of blocking operation as suggested. |
@kavishkamk I would suggest to upgrade and test the application with the latest version |
Same error with "delete", OpenJDK 21
Steps to reproduce: add more samples in import.sql
Start server: run test:
Result:
and server exception:
|
Exception is random.
|
I have the same problem. Simply performance testing the repository "deleteById" method, which is autogenerated by quarkus throws this error. If I replace the implementation with the code below, then delete works as it should (thanks @devorgpl, I have no idea how you managed to discover this). This tells me the problem seems to be in quarkus panache implementation itself. Debugging this is a real PITA.
|
I'm not sure why it fails, but using
I'm still looking into this though |
Nevermind, using the annotation doesn't solve the issue |
@mkouba I think we might need your help with this issue |
I don't think it's Panache, but it seems that the session is created in one thread and then used in another. |
I'm not aware of any annotation that could help here. It seems that the session is opened on the thread that handles the request, in this particular case on the thread that executed the |
I wonder if it's because the |
Well, it should not be a problem since the operations are executed within a single transaction, right? |
Yes, it shouldn't. Unless we are missing something. |
Same problem here Dependencies: ErrorStack: |
We do think that the bug is still relevant 2.5 years later, and might have caused / contributed to #41240 (comment). |
Describe the bug
I'm using the reactive dependencies and I'm running into a use case, where I need to store events asynchronously when my REST endpoint gets hit, without blocking the REST call and delaying the response.
I thought, well, that's easy. Just use SmallRye Emitter, fire an event and the consumer should handle the storing, while the REST call returns the response. Easier said than done, I'm not getting this simple-sounding example to work without this error when I run a load test with up to 20 req/s (error happens much earlier).
Reactive programming is relatively new to me, so it just could be that I'm missing something obvious I have overlooked in the examples.
Expected behavior
No response
Actual behavior
No response
How to Reproduce?
https://github.com/mklueh/quarkus-reproducer-reactive-hibernate-smallrye-messaging
I've created two load-testing scripts that are using k6 in Docker to test both endpoints. Both will fail.
Does not matter which, both lead to the same error.
Output of
uname -a
orver
No response
Output of
java -version
No response
GraalVM version (if different from Java)
No response
Quarkus version or git rev
2.6.3
Build tool (ie. output of
mvnw --version
orgradlew --version
)No response
Additional information
No response
The text was updated successfully, but these errors were encountered: