hibernate-reactive icon indicating copy to clipboard operation
hibernate-reactive copied to clipboard

HR000069: Detected use of the reactive Session from a different Thread

Open dstepanov opened this issue 2 years ago • 10 comments

In Micronaut Data we have a reported issue with Hibernate Reactive and context switching. https://github.com/micronaut-projects/micronaut-data/issues/2165

There can be the following use-case:

  • Open session or TX (Hibernate Reactive opens a sessing and remembers thread ID X)
  • Retrieve something
  • Context switch by accessing another DB or HTTP etc.
    • Thread with ID X is no longer needed; it can be reused for another DB work of Hibernate Reactive.
  • The operation is done and Hibernate Reactive can continue work in the context of the session/tx
  • Here, close session/tx will fail because the thread ID is not equal to X. This doesn't make sense to me because thread X can be used for another operation. The check should only validate that the thread is part of the event loop of the vertx.

Please help me to understand the problem.

dstepanov avatar Jun 12 '23 13:06 dstepanov

Any news on this problem? It's making it very difficult for us to do our jobs. What are the workarounds to this problem now?

uPagge avatar Nov 10 '23 15:11 uPagge

I would be enough if one could manually close the session for me right now.

I am having a non-blocking working service that uses the DB. Works like a charm.

New requirement: Same REST call for clients: In a special case I need to call another blocking HTTP service in case we don't have the information in our Database... either I get warnings that I am blocking in a reactive context or I get the infamous HR000069: Detected use of the reactive Session from a different Thread

If I could just close the session and avoid HR000069 that way and offload to Infrastructure.getDefaultWorkerPool() that would be perfect.

Froidoh avatar Mar 01 '24 10:03 Froidoh

Any update or workaround? I try to use Micronaut with Coroutines but this issue makes it impossible to do

westito avatar Apr 02 '24 06:04 westito

Any updates on this? It cause quite big problem on using Hibernate reactive with Micronaut/Quarkus frameworks

KazimirDobrzhinsky avatar Jun 14 '24 11:06 KazimirDobrzhinsky

I mean the rule here is that the reactive session is tied to a given Vert.x "duplicated" context. You can't share a reactive session between different contexts. This is exactly analogous to how you can't share a session between threads in regular Hibernate.

So you need to ensure that all accesses to a given session happen within the same Vert.x duplicated context.

gavinking avatar Jun 14 '24 11:06 gavinking

https://quarkus.io/guides/duplicated-context

gavinking avatar Jun 14 '24 11:06 gavinking

Can somebody from the Hibernate team provide an example of how to schedule the operation back to the proper context?

dstepanov avatar Jun 14 '24 12:06 dstepanov

Probably not, since we're not experts in either Vert.x or micronaut. I think you would have more luck asking the Vert.x community.

gavinking avatar Jun 14 '24 12:06 gavinking

It can be raw Hibernate Reactive; I will adopt it for Micronaut Data. I just want to see if it's possible. Last time, I spent quite some time and didn't find a way to do it.

dstepanov avatar Jun 14 '24 13:06 dstepanov

I mean if you're just talking about calling out to the database or HTTP then my understanding is that in principle Vert.x is supposed to process the response on the same duplicated context automatically. But there were cases where that wasn't working in Quarkus, which I believe they had to fix on the Quarkus side. But I don't know the details.

gavinking avatar Jun 14 '24 13:06 gavinking