Paternalistic fix for developers with a weak grasp of resource ownership.

pull/611/head
Brett Wooldridge 9 years ago
parent 5eebe56dd1
commit 5c8248732b

@ -251,7 +251,9 @@ public class HikariDataSource extends HikariConfig implements DataSource, Closea
}
/**
* Evict a connection from the pool.
* Evict a connection from the pool. If the connection has already been closed (returned to the pool)
* this may result in a "soft" eviction; the connection will be evicted sometime in the future if it is
* currently in use. If the connection has not been closed, the eviction is immediate.
*
* @param connection the connection to evict from the pool
*/

@ -261,7 +261,12 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL
ProxyConnection proxyConnection = (ProxyConnection) connection;
proxyConnection.cancelLeakTask();
softEvictConnection(proxyConnection.getPoolEntry(), "(connection evicted by user)", true /* owner */);
try {
softEvictConnection(proxyConnection.getPoolEntry(), "(connection evicted by user)", !connection.isClosed() /* owner */);
}
catch (SQLException e) {
// unreachable in HikariCP, but we're still forced to catch it
}
}
public void setMetricRegistry(Object metricRegistry)
@ -524,6 +529,7 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL
private void softEvictConnection(final PoolEntry poolEntry, final String reason, final boolean owner)
{
if (owner || connectionBag.reserve(poolEntry)) {
poolEntry.markEvicted();
closeConnection(poolEntry, reason);
}
else {

Loading…
Cancel
Save