0

I am using Hibernate reactive in combination with Spring WebFlux, recently I started to receive a lot of issues with connections not being closed which results in timeouts when I try to perform the request to the db.

I am using: hibernate-reactive-core: 2.0.0.Final vertx-pg-client: 4.4.2 hibernate: 6.2.4.Final mutiny-reactor: 2.2.0

The issue is there is no stack trace and nothing for me to work with the connection leak could be happening anywhere in the application.

I never use openSession option in the application only withSession and withTransaction.

The only place I use await() option is for the healthcheck, other then that all operations are inside of the reactive context

Did anyone else run into this problem, and what were the issues you have discovered?

I have been working on this bug on and off for quite a while now: things I noticed are:

hibernate reactive hates concurrent updates to the db and could cause an issue when combined using Mono.zip.

I should not use the concurrent operations even search within the same session.

  • This should happen only if the session is never closed. But I don't think you will get an answer without providing a reproducer. – Davide D'Alto Aug 21 '23 at 08:53
  • It could also be a bug. I would probably try to update all the dependencies to the latest version first – Davide D'Alto Aug 21 '23 at 08:54
  • @DavideD'Alto, yeah I know, the issue is that the application is massive and I myself have no idea how to reproduce it, I can only see what happens from the logs, depending on the load on the server after around 20 minutes it fails thee healthchek because of the timed out request. "select true" – Dmytro Kostyushko Aug 23 '23 at 09:45
  • @DavideD'Alto Thank you, but I have already updated dependencies to the latest version, it did not resolve the issue – Dmytro Kostyushko Aug 23 '23 at 09:47
  • @DavideD'Alto, sorry I have a small question, I could not find a definitive answer in the documentation - should we reuse Mutiny.SessionFactory after unwrapping it, or should we unwrap it from EntityManagerFactory each time we need it. I was reusing it before, but I updated my code to always create a new instance, and it looks like it solved the timeout issue, but now I am afraid that it recreates a pool of connections on each request. – Dmytro Kostyushko Aug 23 '23 at 15:59
  • There shouldn't be any reason to recreate a new factory each time. It's an heavy operation and the factory is thread-safe, so there shouldn't be any reason to do so. – Davide D'Alto Aug 23 '23 at 17:28
  • I'm also not familiar with Spring WebFlux and it's likely that you cannot combine it with Hibernate Reactive – Davide D'Alto Aug 23 '23 at 17:30

0 Answers0