swaldman / c3p0

a mature, highly concurrent JDBC Connection pooling library, with support for caching and reuse of PreparedStatements.
http://www.mchange.com/projects/c3p0
Other
1.3k stars 339 forks source link

c3p0 continues attempting connections long after being closed #165

Open hholierhoek opened 1 year ago

hholierhoek commented 1 year ago

c3p0 version is 0.9.5.5, Hibernate version is 5.5.8.Final.

In a scenario where Hibernate was initialized, then quite quickly it got shut down. The c3p0 pool seems to continue trying to create 3 connections though, and is logging the 'APPARENT DEADLOCK' thing periodically.

From thread dumps I can confirm there are no clients still trying to use Hibernate.

PostgreSQL is not accepting connections at this point. The PG connection URL has:

                connectTimeout = 30
                socketTimeout = 600
                tcpKeepAlive = true

Hibernate configuration for c3p0 is:

                hibernate.c3p0.min_size = 1
                hibernate.c3p0.max_size = 64
                hibernate.c3p0.timeout = 60
                hibernate.c3p0.maxStatementsPerConnection = 250
                hibernate.c3p0.testConnectionOnCheckout = true
                hibernate.c3p0.checkoutTimeout = 60000
                hibernate.c3p0.validationQuery = select 1

The 'deadlock' stack trace log:


com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@16b56fdd -- APPARENT DEADLOCK!!! Complete Status:
        Managed Threads: 3
        Active Threads: 3
        Active Tasks:
                com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@13ec640a
                        on thread: C3P0PooledConnectionPoolManager[identityToken->30zrwcas1h8bo5r1rgqng3|47c65313]-HelperThread-#0
                com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@752bd16d
                        on thread: C3P0PooledConnectionPoolManager[identityToken->30zrwcas1h8bo5r1rgqng3|47c65313]-HelperThread-#1
                com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@73ab5f9d
                        on thread: C3P0PooledConnectionPoolManager[identityToken->30zrwcas1h8bo5r1rgqng3|47c65313]-HelperThread-#2
        Pending Tasks:
                com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@4cb78b99
                com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@3c0b6a31
                com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@17806464
Pool thread stack traces:
        Thread[C3P0PooledConnectionPoolManager[identityToken->30zrwcas1h8bo5r1rgqng3|47c65313]-HelperThread-#0,5,main]
                java.net.PlainSocketImpl.socketConnect(Native Method)
                java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
                java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
                java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
                java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
                java.net.Socket.connect(Socket.java:607)
                org.postgresql.core.PGStream.<init>(PGStream.java:69)
                org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:152)
                org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
                org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195)
                org.postgresql.Driver.makeConnection(Driver.java:454)
                org.postgresql.Driver.connect(Driver.java:256)
                com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
                com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
                com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
                com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
                com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1176)
                com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1163)
                com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
                com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1908)
                com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
        Thread[C3P0PooledConnectionPoolManager[identityToken->30zrwcas1h8bo5r1rgqng3|47c65313]-HelperThread-#2,5,main]
                java.net.PlainSocketImpl.socketConnect(Native Method)
                java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
                java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
                java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
                java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
                java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
                java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
                java.net.Socket.connect(Socket.java:607)
                org.postgresql.core.PGStream.<init>(PGStream.java:69)
                org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:152)
                org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
                org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195)
                org.postgresql.Driver.makeConnection(Driver.java:454)
                org.postgresql.Driver.connect(Driver.java:256)
                com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
                com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
                com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
                com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
                com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1176)
                com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1163)
                com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
                com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1908)
                com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
        Thread[C3P0PooledConnectionPoolManager[identityToken->30zrwcas1h8bo5r1rgqng3|47c65313]-HelperThread-#1,5,main]
                java.net.PlainSocketImpl.socketConnect(Native Method)
                java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
                java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
                java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
                java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
                java.net.Socket.connect(Socket.java:607)
                org.postgresql.core.PGStream.<init>(PGStream.java:69)
                org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:152)
                org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
                org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195)
                org.postgresql.Driver.makeConnection(Driver.java:454)
                org.postgresql.Driver.connect(Driver.java:256)
                com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
                com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
                com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
                com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
                com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1176)
                com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1163)
                com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
                com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1908)
                com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)```
swaldman commented 9 months ago

It looks like the pool didn't get shut down (i.e. with ComboPooledDataSource.close()), and the Connection attempts are neither succeeding nor failing promptly with an Exception, but just hanging, despite the connectTimeout.