question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Agroal leaks XA connections

See original GitHub issue

Describe the bug

Thy physical database connections backing XA connections are never closed properly but instead leaked.

I’ve added the issue to the Agroal JIRA AG-165 which attempts to explain in detail the possible origin of the issue. I am cross-posting because of the familiarity of these two projects and if this issue is proven correct it’s a fairly serious one that affects Quarkus directly.

Expected behavior

Physical connections backing XA connections are cleaned up when closed.

Actual behavior

Physical connections are leaked and the driver’s leak detection must handle their closure.

To Reproduce

I’ve built a repro in Quarkus that shows that two PostgreSQL drivers (mainstream pgjdbc & alternate pgjdbc-ng) never have their XA connections closed; instead they are leaked. The mainstream pgjdbc driver implements finalize and cleans up the connections that way with no warnings/logs. The alternate pgjdbc-ng driver cleans up the connections via phantom reference queues; this driver logs warnings about the leaks as well.

Running the repo tests (via ./gradlew test) with the pgjdbc-ng driver you will see leaks logged.

Debugging the tests with either driver will allow you to breakpoint/breaklog the close method of either driver’s physical connection implementation (PgConnection for pgjdbc / PGDirectConnection for pgjdbc-ng) and see that the close is only ever called in finalize or via phantom reference cleanup.

NOTE to select which driver to target while running you must uncomment the right options in application.properties. code-with-quarkus.zip

Configuration


quarkus.datasource.db-kind=postgresql
quarkus.datasource.username=test
quarkus.datasource.password=test
quarkus.datasource.jdbc.driver=com.impossibl.postgres.jdbc.xa.PGXADataSource
quarkus.datasource.jdbc.url=jdbc:pgsql://localhost:5432/test
#quarkus.datasource.jdbc.driver=org.postgresql.xa.PGXADataSource
#quarkus.datasource.jdbc.url=jdbc:postgresql://localhost:5432/test
quarkus.datasource.jdbc.transactions=xa
quarkus.datasource.jdbc.initial-size=3
quarkus.datasource.jdbc.min-size=1
quarkus.datasource.jdbc.max-size=20
quarkus.datasource.jdbc.idle-removal-interval=2S
quarkus.datasource.jdbc.enable-metrics=true

quarkus.flyway.migrate-at-start=true

Environment (please complete the following information):

Output of uname -a or ver

Darwin host.local 20.3.0 Darwin Kernel Version 20.3.0: Thu Jan 21 00:07:06 PST 2021; root:xnu-7195.81.3~1/RELEASE_X86_64 x86_64

Output of java -version

java version "11.0.6" 2020-01-14 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.6+8-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.6+8-LTS, mixed mode)

Quarkus version or git rev

1.12.21

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


------------------------------------------------------------
Gradle 6.8.3
------------------------------------------------------------

Build time:   2021-02-22 16:13:28 UTC
Revision:     9e26b4a9ebb910eaa1b8da8ff8575e514bc61c78

Kotlin:       1.4.20
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          14 (Oracle Corporation 14+36-1461)
OS:           Mac OS X 10.16 x86_64

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:16 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
kdubbcommented, Apr 15, 2021

@gsmet Yes. Will confirm here soon.

0reactions
kdubbcommented, Apr 17, 2021

@gsmet @barreiro Switching to 1.13.2 removes all of our leaked connection warnings. 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Datasources - Quarkus
Agroal is a modern, lightweight connection pool implementation designed for very high performance and scalability, ... Database kind, JDBC driver, XA driver ...
Read more >
The AgroalDatasource class
Agroal library allows the definition of java.sql.DataSource with connection pooling. This guide goes over what does Agroal provide and the configurations ...
Read more >
How to Prevent JDBC Resource Leaks with JDBC ... - jOOQ blog
Fix #2: Use jOOQ, which manages resources for you · JDBC DataSource / Connection => jOOQ ConnectionProvider : jOOQ doesn't know the concept...
Read more >
Chapter 13. Datasource Management With Agroal
A new datasources-agroal subsystem was introduced in JBoss EAP 7.2. This is a new high performance direct connection pool backed by the Agroal...
Read more >
JDBC Connection Pool Leak causing Connections to Grow to ...
A JDBC connection pool leak was found in WebLogic Server 10.3.2 ... At the next database access in the XA transaction will fail...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found