Agroal leaks XA connections
See original GitHub issueDescribe 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:
- Created 2 years ago
- Comments:16 (12 by maintainers)
@gsmet Yes. Will confirm here soon.
@gsmet @barreiro Switching to
1.13.2
removes all of our leaked connection warnings. 👍