Connection leaked on rollback with mode DELAYED_ACQUISITION_AND_RELEASE_BEFORE_TRANSACTION_COMPLETION

Description

Originally reported by Jan Kunzmann: thanks to him!

Reproducer (in Quarkus): https://github.com/suchwerk/quarkus-hibernate-search-massindexer
You'll need to start an Elasticsearch container, then run the tests:

May be the same thing as HHH-14266, though I'm not entirely sure: in our case, everything happens in a single thread.

On commit, org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl#beforeCompletion will be called and will close the connection. But not on rollback. And it seems we don't have anything to close the connection on rollback?

Environment

None

Activity

Show:
Yoann Rodière
April 14, 2021, 6:29 AM

I believe the best strategy would be to close the connection as soon as a rollback occurs, if possible. I agree it may not be easy to achieve

Indeed. We don’t really have a hook for that.

We may do that in the future, but for now I’ll make sure that we will at least close the connection after the rollback (afterTransactionCompletion). At least that way ORM will be aware that the connection was closed and won’t trigger exceptions (“Connection is closed”) by reusing the connection for the next transaction.

We will iterate if we find better solutions.

Luis Barreiro
April 13, 2021, 11:23 PM

I had a look at this issue for AG-168 and I believe the best strategy would be to close the connection as soon as a rollback occurs, if possible. I agree it may not be easy to achieve.

A note that Narayana has a setting for invoking beforeCompletion() on rollbacks too, but that setting was not effective on the use case I had. Even if it were, I’m not convinced it would be something that should be relied upon.

It seems that the API was designed after prepare() on the XA API, leaving out the rollback scenario. That is kinda unfortunate but there is not much that can be done around that now.

Yoann Rodière
April 13, 2021, 12:35 PM
Fixed

Assignee

Yoann Rodière

Reporter

Yoann Rodière

Fix versions