Close connections marked as evicted instead of returning them to the pool (#2157)

pull/2241/head
Thomas Aregger 4 months ago committed by GitHub
parent aeabea98b7
commit a671b6e24d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -417,8 +417,11 @@ public final class HikariPool extends PoolBase implements HikariPoolMXBean, IBag
void recycle(final PoolEntry poolEntry)
{
metricsTracker.recordConnectionUsage(poolEntry);
connectionBag.requite(poolEntry);
if (poolEntry.isMarkedEvicted()) {
closeConnection(poolEntry, EVICTED_CONNECTION_MESSAGE);
} else {
connectionBag.requite(poolEntry);
}
}
/**

@ -310,6 +310,28 @@ public class TestConnections
}
}
@Test
public void testCloseMarkEvicted() throws Exception
{
HikariConfig config = newHikariConfig();
config.setMinimumIdle(0);
config.setMaximumPoolSize(5);
config.setConnectionTimeout(2500);
config.setConnectionTestQuery("VALUES 1");
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
try (HikariDataSource ds = new HikariDataSource(config)) {
ProxyConnection connection = (ProxyConnection) ds.getConnection();
HikariPool pool = getPool(ds);
assertEquals(1, pool.getTotalConnections());
connection.getPoolEntry().markEvicted();
connection.close();
assertEquals("Connection should have been evicted after close", 0, pool.getTotalConnections());
}
}
@Test
public void testEviction() throws Exception
{

Loading…
Cancel
Save