quarkus: Incorrect "WARN Closing open connection prior to commit" when handling BEFORE_COMMIT event

Describe the bug

When using javax.enterprise.event Events and an Observer with TransactionPhase.BEFORE_COMPLETION that queries anything with sql the WARN log WARN [io.agr.pool] (executor-thread-0) Datasource '<default>': Closing open connection prior to commit appears.

Expected behavior

No WARN log, as everything works as intended.

Actual behavior

Logs WARN [io.agr.pool] (executor-thread-0) Datasource '<default>': Closing open connection prior to commit

How to Reproduce?

Open the quarkus hibernate-orm-quickstart project.

  1. add @Inject Event<Fruit> eventBus; in the FruitResource
  2. add eventBus.fire(fruit); in the create method
  3. create class ExampleEventObserver:
public class ExampleEventObserver
{
    @Inject
    EntityManager entityManager;

    public void beforeCompletion(@Observes(during = TransactionPhase.BEFORE_COMPLETION) Fruit exampleEvent) {
        // do some query -> this triggers the warning
        List<Fruit> resultList = entityManager.createNamedQuery("Fruits.findAll", Fruit.class).getResultList();
        System.out.println("done with example event");
    }
}
  1. start FruitsEndpointTest.testListAllFruits and you will see the warning log directly underneath the “done with example event”

Output of uname -a or ver

Microsoft Windows [Version 10.0.19042.928]

Output of java -version

java version “11.0.5” 2019-10-15 LTS Java™ SE Runtime Environment 18.9 (build 11.0.5+10-LTS) Java HotSpot™ 64-Bit Server VM 18.9 (build 11.0.5+10-LTS, mixed mode)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

1.13.6.FINAL and 2.0.2.FINAL

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

Apache Maven 3.6.3

Additional information

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 36 (24 by maintainers)

Most upvoted comments

I talked about this with @ochaloup and we came to a conclusion that Arc should use standard synchronization rather than interposed. One of the reasons being that this is really of a user-invoked synchronization rather than a container-invoked one which makes usage of interposed synch dubious.

As to what is described in eclipse-ee4j/cdi#467 plus the configurable option - the CDI issue isn’t completely legitimate request because there would first have to be adjustments on JTA spec side. From what I understood (@ochaloup will correct me if I am wrong), JTA cannot guarantee entity manager state at that point making this requirement a non-portable one anyway. So I would refrain from implementing the config yet but I will leave a note in the code for future reference. It would be easily implementable but unless we have the requirement, I don’t think we want to introduce extra config options.

Will send a PR to fix the Arc-side of this issue shortly.

Let me clarify a couple of things:

  • The DELAYED_ACQUISITION_AND_RELEASE_BEFORE_COMPLETION strategy has already been benchmarked, and we’d want to keep this choice if possible as there are meaningul benefits.
  • There is no JCA integration and we don’t plan to have support for JCA in Quarkus.
  • Don’t worry about “portability” issues - this is a single, opinionated platform which means components can’t be swapped out freely.

Many thanks @manovotn for stepping in on the Arc side - that seems like the sensible solution.

What impact would an application library registering a sync have on this ordering scheme?

The way I coded it [1] means that such an interposed sync will run after the ARC ones but before the Agroal ones. Apart from that caveat all other interposed syncs will be ordered in the order that they were registered.

Would it help to instead ensure that Hibernate ORM syncs (perhaps both before/after competition) always run last?

The Agroal afterCompletion synchronization [2,3] needs to run last: it checks that all of the connection wrappers are closed and it returns the connection back to the connection pool. But I could run the Hibernate ORM syncs after the other ones, so [ARC, other syncs, Hibernate, Agroal]? (Narayana runs the afterCompletions in reverse order compared to beforeCompletions and we would want to maintain that policy).

[1] https://github.com/quarkusio/quarkus/compare/2.0.2.Final...mmusgrov:quarkus:18737-synch-order-on-2.0.2.Final?expand=1#diff-eb042caa54555177c75fa37d6a25c9718840b45ee89997cf60fea2d6e5e15331R85 [2] https://github.com/agroal/agroal/blob/1.11/agroal-narayana/src/main/java/io/agroal/narayana/NarayanaTransactionIntegration.java#L188 [3] https://github.com/agroal/agroal/blob/1.11/agroal-pool/src/main/java/io/agroal/pool/ConnectionHandler.java#L332

I will propose a narayana-jta extension change and base it on WLFY-3619 which adds similar functionality for WildFly by wrapping the TSR.