-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Hibernate Reactive: ReactiveSessionProducer blocks event loop thread #18268
Comments
/cc @DavideD, @Sanne, @gavinking |
Very interesting, thanks @markusdlugi ! |
@cescoffier . @gavinking I'm going to need a suggestion here, this seems to highlight multiple problems:
WorkaroundI honestly don't know how to solve this in a clean way; I'm thinking to apply the following should-work bandaid: rather than converting this into a CompletionStage, I'll subscribe on it (not sure which kind to subscription to use), and store a reference in a ThreadLocal. Then any subsequent invocation on WDYT? I could also use some suggestions for testing; I'm going to play with the idea and measure impact under load. |
Actually to go with my workaround I would also need to change the CDI producer from type |
so I have a POC which works fine, but injecting a
wouldn't anyone prefer injecting the SessionFactory instead: ?
So I'm inclined to proceed testing this change but expect this lookup strategy to be used by Panache exclusively; and perhaps we shouldn't expose this as a CDI bean but move this logic into Panache. cc/ @FroMage Please let me know if you see a simpler way forward |
Damn, this change has caused multiple bugs, one at each level. Ouch.
So I think it would make sense to add some sort of non-blocking equivalent. However, here what I would do is instead of using |
I think that's what I was doing in my code examples. |
I'm not quite sure what you mean by this, but it sounds very fragile and possibly broken to me. |
|
I wish.. we don't have a stream since the CDI entry points are blocking - or did I not understand your idea?
Yeah me too: and that's why I'm raising this to you and Clement: the notions of contexts from CDI doesn't integrate well. FWIW I was originally planning to remove all reactive X.Session producers but the way Panache works you need a notion of "the current session", for those static methods injected on the entities to make sense.
Sure I hate it. Which is why I'm referring to it as "bandaid" and workaround - IMO a proper solution would require to design of proper semantics at ARC / CDI level, for example to allow declaring reactive versions of both producers and disposers - which the implementation would need to wire up correctly with other components on the stack, so that assuming the other ones are also reactive it all works well. (Not sure what to do when some do not but that's a different discussion also addressed on the mailing list). However, consider that the request scope is modelled as a simple threadlocal in ArC - and these are request scoped components. So while I agree it's fragile and horrible, it could work fine until the greater design issue is addressed? |
in an interceptor |
I think the notions work fine. I think we simply have not integrated them well, because we have not adjusted our thinking to what contexts make sense in a reactive invocation. We're trying to just literalistically carry ideas directly over from servlets and of course they don't make sense because the threading model is just different. I was talking about this with Max and Emmanuel today.
That is probably better, but it still seems to me that you can do this in an interceptor. (Just like you can do tx management in an interceptor.) |
Well as I've been advocating in a different place, as long as the "request context" maps directly to a Vert.x context, we're fine, I think. |
I don't mind at all if Panache gets its session from somewhere else than this producer, I just didn't want to introduce a second storage for it as long as it existed. |
I've taken a step back from the more complicated solution I mentioned early and went with this: I believe it should work because we technically don't really need to wait for this to have happened in such an aggressive way: the availability of connections on the pool will provide a natural ordering, prioritizing operations which close sessions over opening when saturated. |
yea I think that's reasonable. If the producer exists from CDI we should make sure that Panache uses the same Session instance. On the other hand, I'll consider removing all CDI producers and provide an alternative for Panache. Creating a new Session and storing one in the Vertx context is easy.. the tricky part is to define when the scope should end. |
(I've just closed this issue BTW) |
Describe the bug
Most likely since Quarkus 2.0.0.Alpha2 with the introduction of these changes, Hibernate Reactive can sometimes block the event loop thread forever if injecting
Mutiny.Session
via theReactiveSessionProducer
, making the entire application unresponsive.Expected behavior
Hibernate Reactive should properly dispose its sessions without blocking.
Actual behavior
It is actually blocking the event loop thread. See the following thread dump from one of our applications. The thread remains in this state forever. As a consequence, the entire application cannot handle any incoming requests anymore.
To Reproduce
Haven't yet been able to create a reproducer, but most likely happens when some failure happens in a reactive chain where HR was previously used (not necessarily in Hibernate itself).
Configuration
# Add your application.properties here, if applicable.
Screenshots
(If applicable, add screenshots to help explain your problem.)
Environment (please complete the following information):
Output of
uname -a
orver
Microsoft Windows [Version 10.0.18363.1556]
Output of
java -version
OpenJDK 64-Bit Server VM Corretto-11.0.10.9.1 (build 11.0.10+9-LTS, mixed mode)
GraalVM version (if different from Java)
N/A
Quarkus version or git rev
2.0.0.Final
Build tool (ie. output of
mvnw --version
orgradlew --version
)Apache Maven 3.6.3
Additional context
(Add any other context about the problem here.)
The text was updated successfully, but these errors were encountered: