quarkus: [PosgreSQL] JDBCConnectionException: Unable to release JDBC Connection
Describe the bug Unable to release connection using PostgreSQL + 1.1.0.Final/1.1.1.Final AND testcontainers
Expected behavior With 1.0.1.Final, the same integration test (using testcontainers) was working perfectly. Upgrading to 1.1.0.Final makes it break every time.
Actual behavior Running the same integration test (spawning a pg image using testcontainers, running a query, shutting down the test suite) fails with the following exception:
Caused by: org.hibernate.exception.JDBCConnectionException: Unable to release JDBC Connection
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:112)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.releaseConnection(LogicalConnectionManagedImpl.java:195)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.afterStatement(LogicalConnectionManagedImpl.java:147)
at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.afterStatementExecution(JdbcCoordinatorImpl.java:265)
at org.hibernate.loader.Loader.getResultSet(Loader.java:2298)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2050)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2012)
at org.hibernate.loader.Loader.doQuery(Loader.java:953)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354)
at org.hibernate.loader.Loader.doList(Loader.java:2815)
at org.hibernate.loader.Loader.doList(Loader.java:2797)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2629)
at org.hibernate.loader.Loader.list(Loader.java:2624)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:506)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:396)
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:219)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1396)
at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1558)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1526)
... 75 more
Caused by: org.postgresql.util.PSQLException: This connection has been closed.
at org.postgresql.jdbc.PgConnection.checkClosed(PgConnection.java:782)
at org.postgresql.jdbc.PgConnection.getWarnings(PgConnection.java:681)
at io.agroal.pool.ConnectionHandler.resetConnection(ConnectionHandler.java:129)
at io.agroal.pool.ConnectionPool.returnConnectionHandler(ConnectionPool.java:308)
at io.agroal.pool.ConnectionHandler.onConnectionWrapperClose(ConnectionHandler.java:100)
at io.agroal.pool.wrapper.ConnectionWrapper.close(ConnectionWrapper.java:135)
at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.closeConnection(DatasourceConnectionProviderImpl.java:127)
at org.hibernate.internal.NonContextualJdbcConnectionAccess.releaseConnection(NonContextualJdbcConnectionAccess.java:49)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.releaseConnection(LogicalConnectionManagedImpl.java:192)
... 92 more
To Reproduce Steps to reproduce the behavior:
- Create a simple service and
@InjectanEntityManager - In some method, perform an HQL query and return
query.getResultList() - Use this method in a
QuarkusTesttogether withTestContainers
In the logs, I can see:
INFO: Container my-pg-database-full-of-data:latest started in PT10.073976S
janv. 06, 2020 5:33:34 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 0, SQLState: 57P01
57P01 seems to be admin_shutdown, so my guess would be that TestContainers is requesting the container to shut down before the actual quarkus test finishes.
The only thing I changed is Quarkus version, code didn’t change, did not upgrade test-containers dependency neither, same docker pg image containing the same data (actually using my local cache).
Works perfectly fine in 1.0.1.Final, crashes in 1.1.0.Final
Do you have any idea what could create such a behavior (a 3rd-party dependency upgrade between 1.0.1.Final and 1.1.0.Final maybe?), anything I could investigate on, basically! 😃
Thanks
Configuration
# Add your application.properties here, if applicable.
# HTTP Server config
quarkus.http.port=9090
# DataSource
quarkus.datasource.driver=org.postgresql.Driver
quarkus.datasource.url=jdbc:postgresql://localhost:5432/somedb
quarkus.datasource.username=thelogin
quarkus.datasource.password=thepwd
# Hibernate
quarkus.hibernate-orm.dialect=org.hibernate.dialect.PostgreSQL95Dialect
#quarkus.hibernate-orm.log.sql=true
quarkus.datasource.min-size=10
quarkus.datasource.max-size=100
Environment (please complete the following information):
- Quarkus version or git rev: either 1.1.0.Final or 1.1.1.Final
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 23 (8 by maintainers)
Thank you so much for the reproducer! I really struggled to create one. This helps a lot.
I ran into the same issue:
I created a reproducer here: https://github.com/misl/QuarkusIssueReproducer The reproducer is basically the Hero service from the workshop. Only change is that there are 2 (identical) @QuarkusTest annotated classes HeroResourceTest and Hero2ResourceTest with the container stuff moved to a base HeroTestBase class. If either one of the ResourceTest classes is removed the tests run just fine.
Hope this helps to resolve the problem.
I’ll try to, but that’s gonna be a hard task. The docker image I’m using for my tests is a PgSQL one, but containing a subset of real-life data.
For the reproducer to be public I’d need to publish such an image to a public docker registry.
That’s why I was hoping for Clément’s repo to have the same issue. But it doesn’t (I ran it locally).
No seriously, I have absolutely no clue what’s going on with versions >= 1.0.1.Final there must some weird race condition happening, (maybe with ryuk?), but the only thing I’m actually evidencing is that “something” is requesting the PostgreSQL database to shutdown (admin shutdown actually), before the test is actually finished.
I completely understand you can’t work without reproducer, but I don’t manage to create a proper one.
Some science-fictional guess would be that this change messed-up Ryuk (=the thing testcontainers uses to manage docker images) a bit like the bug happening here but I can’t find a way to evidence it.
Sorry :\