ActiveMQ在XA事务回滚时泄漏数据库连接

时间:2017-05-17 17:49:42

标签: java postgresql activemq c3p0

我们正在使用带有c3p0 0.9.5.2的ActiveMQ 5.14.2来管理与Postgres的数据库连接池的持久性。运行几天后,ActiveMQ将无法响应,我在Postgres中观察到大量长时间运行的空闲连接,并带有以下查询:

SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

要调试此问题,我在c3p0中启用了unreturnedConnectionTimeout和debugUnreturnedConnectionStackTraces设置,这会产生以下堆栈跟踪:

2017-05-17 22:37:18,559 [C3P0PooledConnectionPoolManager[identityToken->2y6m349o6vml11guusw6|1e1340a]-AdminTaskTimer] INFO  com.mchange.v2.resourcepool.BasicResourcePool.log(Slf4jMLog.java:215) - Logging the stack trace by which the overdue resource was checked-out.
java.lang.Exception: DEBUG STACK TRACE: Overdue resource check-out stack trace.
    at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:588)[c3p0-0.9.5.2.jar:0.9.5.2]
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse(C3P0PooledConnectionPool.java:758)[c3p0-0.9.5.2.jar:0.9.5.2]
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:685)[c3p0-0.9.5.2.jar:0.9.5.2]
    at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140)[c3p0-0.9.5.2.jar:0.9.5.2]
    at org.apache.activemq.store.jdbc.TransactionContext.lockAndWrapped(TransactionContext.java:70)[activemq-jdbc-store-5.14.3.jar:5.14.3]
    at org.apache.activemq.store.jdbc.TransactionContext.getConnection(TransactionContext.java:63)[activemq-jdbc-store-5.14.3.jar:5.14.3]
    at org.apache.activemq.store.jdbc.TransactionContext.begin(TransactionContext.java:192)[activemq-jdbc-store-5.14.3.jar:5.14.3]
    at org.apache.activemq.store.jdbc.JDBCPersistenceAdapter.beginTransaction(JDBCPersistenceAdapter.java:510)[activemq-jdbc-store-5.14.3.jar:5.14.3]
    at org.apache.activemq.store.jdbc.JdbcMemoryTransactionStore.rollback(JdbcMemoryTransactionStore.java:165)[activemq-jdbc-store-5.14.3.jar:5.14.3]
    at org.apache.activemq.transaction.XATransaction.rollback(XATransaction.java:146)[activemq-broker-5.14.3.jar:5.14.3]
    at org.apache.activemq.broker.TransactionBroker.rollbackTransaction(TransactionBroker.java:257)[activemq-broker-5.14.3.jar:5.14.3]
    at org.apache.activemq.broker.BrokerFilter.rollbackTransaction(BrokerFilter.java:148)[activemq-broker-5.14.3.jar:5.14.3]
    at org.apache.activemq.broker.BrokerFilter.rollbackTransaction(BrokerFilter.java:148)[activemq-broker-5.14.3.jar:5.14.3]
    at org.apache.activemq.broker.BrokerFilter.rollbackTransaction(BrokerFilter.java:148)[activemq-broker-5.14.3.jar:5.14.3]
    at org.apache.activemq.broker.MutableBrokerFilter.rollbackTransaction(MutableBrokerFilter.java:153)[activemq-broker-5.14.3.jar:5.14.3]
    at org.apache.activemq.broker.TransportConnection.processRollbackTransaction(TransportConnection.java:556)[activemq-broker-5.14.3.jar:5.14.3]
    at org.apache.activemq.command.TransactionInfo.visit(TransactionInfo.java:104)[activemq-client-5.14.3.jar:5.14.3]
    at org.apache.activemq.broker.TransportConnection.service(TransportConnection.java:336)[activemq-broker-5.14.3.jar:5.14.3]
    at org.apache.activemq.broker.TransportConnection$1.onCommand(TransportConnection.java:200)[activemq-broker-5.14.3.jar:5.14.3]
    at org.apache.activemq.transport.MutexTransport.onCommand(MutexTransport.java:50)[activemq-client-5.14.3.jar:5.14.3]
    at org.apache.activemq.transport.WireFormatNegotiator.onCommand(WireFormatNegotiator.java:125)[activemq-client-5.14.3.jar:5.14.3]
    at org.apache.activemq.transport.AbstractInactivityMonitor.onCommand(AbstractInactivityMonitor.java:301)[activemq-client-5.14.3.jar:5.14.3]
    at org.apache.activemq.transport.TransportSupport.doConsume(TransportSupport.java:83)[activemq-client-5.14.3.jar:5.14.3]
    at org.apache.activemq.transport.tcp.TcpTransport.doRun(TcpTransport.java:233)[activemq-client-5.14.3.jar:5.14.3]
    at org.apache.activemq.transport.tcp.TcpTransport.run(TcpTransport.java:215)[activemq-client-5.14.3.jar:5.14.3]
    at java.lang.Thread.run(Thread.java:745)[:1.7.0_80]

这似乎表明XATransaction.rollback保持连接打开的问题。任何人都可以建议解决这个问题,因为不建议将unreturnedConnectionTimeout用于生产用途吗?以下是我的c3p0配置:

<bean id="postgres-ds" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
            <property name="driverClass" value="org.postgresql.Driver" />
            <property name="jdbcUrl" value="jdbc:postgresql://localhost:5432/activemq" />
            <property name="user" value="amq_user" />
            <property name="password" value="**********" />
            <property name="maxStatementsPerConnection" value="20"/>
            <property name="initialPoolSize" value="3" />
            <property name="minPoolSize" value="3" />
            <property name="maxPoolSize" value="40" />
            <property name="maxIdleTime" value="1800" />
            <property name="maxIdleTimeExcessConnections" value="120" />
            <property name="numHelperThreads" value="10" />
            <property name="testConnectionOnCheckout" value="true"/>
            <property name="idleConnectionTestPeriod" value="60" />
            <property name="preferredTestQuery" value="SELECT 1" />
            <property name="unreturnedConnectionTimeout" value="300" />
            <property name="debugUnreturnedConnectionStackTraces" value="true" />
    </bean>

0 个答案:

没有答案