Skip to content

Hibernate Reactive 2.4.6 combined with Panache can violate transaction boundaries #47314

@markusdlugi

Description

@markusdlugi

Describe the bug

We tried to update our application to use Hibernate Reactive 2.4.6 to fix hibernate/hibernate-reactive#2007. While most of our tests worked, we observed one behavior that is concerning and indicates to us that the transaction boundaries are not respected correctly. Specifically, this seems to happen when mixing Panache and Vanilla Hibernate Reactive, e.g. because some specific queries need a SessionFactory.

One example we observed:

  • Fetch an entity using Panache repository with PESSIMSTIC_WRITE lock and then wait (using a delay)
  • Fetch the same entity using SessionFactory with PESSIMISTIC_WRITE
  • Observe that both transactions obtain the lock at the same time (or rather, it seems to be a single transaction instead of two distinct ones?)

Expected behavior

We expect transaction boundaries to be respected. In the given example, the second transaction should need to wait until the first transaction released the lock before it can acquire it.

Actual behavior

As described, locks can be shared between seemingly distinct transactions. Most likely there are other negative side effects.

How to Reproduce?

Reproducer: https://github.com/markusdlugi/hr-transaction-reproducer

Steps to reproduce the behavior:

  1. Run CounterResourceTest
  2. Observe that should_increase_count_sequentially_using_only_panache() is always successful, while should_increase_count_sequentially_using_panache_and_hr_session() will occasionally fail
  3. Change dependency to use Hibernate Reactive 2.4.5.Final
  4. Observe that all tests are successful

Output of uname -a or ver

No response

Output of java -version

No response

Quarkus version or git rev

3.21.1

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

This behavior can only be reproduced with Hibernate Reactive 2.4.6.Final. Using HR 2.4.5.Final, everything is working as expected.

We suspect that hibernate/hibernate-reactive#2198 might be the root cause, but not quite sure.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions