Skip to content

Commit dcfa458

Browse files
committed
Bad connection issue if autoCommit = false
The issue is appear in the flowing case: - if autoCommit = false - poolPingEnabled = true and poolPingQuery is set - number of connections in the pool = poolMaximumActiveConnections - connection state.activeConnections.get(0) is bad, for example database was restarted. Currently the following is happened: we are trying to execute sql query (query1) with the new connection getting and have the following: state.activeConnections.remove(oldestActiveConnection); if (!oldestActiveConnection.getRealConnection().getAutoCommit()) { oldestActiveConnection.getRealConnection().rollback(); } so the old connection is removed from the pool and we are trying to rollback it. But connection is bad and it throws an exception so method stops execution. The issue here: sql query (query1) execution will never be executed - we lost it forever. if AutoCommit = true - rollback is not needed and method will continue execution and will be reconnected at the end and query1 will not be lost. Thanks, Natalia
1 parent c02d817 commit dcfa458

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/main/java/org/apache/ibatis/datasource/pooled/PooledDataSource.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,11 @@ private PooledConnection popConnection(String username, String password) throws
397397
state.accumulatedCheckoutTime += longestCheckoutTime;
398398
state.activeConnections.remove(oldestActiveConnection);
399399
if (!oldestActiveConnection.getRealConnection().getAutoCommit()) {
400-
oldestActiveConnection.getRealConnection().rollback();
400+
try {
401+
oldestActiveConnection.getRealConnection().rollback();
402+
} catch (SQLException e) {
403+
log.debug("Bad connection. Could not roll back");
404+
}
401405
}
402406
conn = new PooledConnection(oldestActiveConnection.getRealConnection(), this);
403407
oldestActiveConnection.invalidate();

0 commit comments

Comments
 (0)