Fixes #983 fix logic that determines how many idle connections can be removed, without violating the minimumIdle contract.

pull/991/head
Brett Wooldridge 8 years ago
parent 6735fcfe3a
commit d6a9cd435c

@ -696,13 +696,11 @@ public final class HikariPool extends PoolBase implements HikariPoolMXBean, IBag
afterPrefix = "After cleanup "; afterPrefix = "After cleanup ";
final List<PoolEntry> notInUse = connectionBag.values(STATE_NOT_IN_USE); final List<PoolEntry> notInUse = connectionBag.values(STATE_NOT_IN_USE);
int removed = 0; int toRemove = notInUse.size() - config.getMinimumIdle();
for (PoolEntry entry : notInUse) { for (PoolEntry entry : notInUse) {
if (elapsedMillis(entry.lastAccessed, now) > idleTimeout && connectionBag.reserve(entry)) { if (toRemove > 0 && elapsedMillis(entry.lastAccessed, now) > idleTimeout && connectionBag.reserve(entry)) {
closeConnection(entry, "(connection has passed idleTimeout)"); closeConnection(entry, "(connection has passed idleTimeout)");
if (++removed > config.getMinimumIdle()) { toRemove--;
break;
}
} }
} }
} }

Loading…
Cancel
Save