Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
use unique pool names (#5963)
Browse files Browse the repository at this point in the history
Use a global counter to avoid conflicts in hikari pool name. If the old exception handling code was hit, an executor would be leaked due to a bug in hikari.
  • Loading branch information
rzpt authored Mar 15, 2022
1 parent 568503e commit 366e1ac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
import java.sql.SQLException;
import java.sql.Statement;
import java.util.TimeZone;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import javax.management.JMX;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
Expand All @@ -53,6 +53,8 @@
public class HikariCPConnectionManager extends BaseConnectionManager {
private static final SafeLogger log = SafeLoggerFactory.get(HikariCPConnectionManager.class);

private static final AtomicLong uniquePoolId = new AtomicLong(0L);

private final ConnectionConfig connConfig;
private final HikariConfig hikariConfig;

Expand Down Expand Up @@ -86,6 +88,7 @@ private static class State {
public HikariCPConnectionManager(ConnectionConfig connConfig) {
this.connConfig = Preconditions.checkNotNull(connConfig, "ConnectionConfig must not be null");
this.hikariConfig = connConfig.getHikariConfig();
hikariConfig.setPoolName(hikariConfig.getPoolName() + "-" + uniquePoolId.incrementAndGet());
}

@Override
Expand Down Expand Up @@ -300,20 +303,7 @@ private HikariDataSource getDataSourcePool() {
HikariDataSource dataSourcePool;

try {
try {
dataSourcePool = new HikariDataSource(hikariConfig);
} catch (IllegalArgumentException e) {
// allow multiple pools on same JVM (they need unique names / endpoints)
if (e.getMessage().contains("A metric named")) {
String poolName = connConfig.getConnectionPoolName();

hikariConfig.setPoolName(
poolName + "-" + ThreadLocalRandom.current().nextInt());
dataSourcePool = new HikariDataSource(hikariConfig);
} else {
throw e;
}
}
dataSourcePool = new HikariDataSource(hikariConfig);
} catch (PoolInitializationException e) {
log.error(
"Failed to initialize hikari data source",
Expand Down
7 changes: 7 additions & 0 deletions changelog/@unreleased/pr-5963.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type: fix
fix:
description: Use a global counter to avoid conflicts in hikari pool name. If the
old exception handling code was hit, an executor would be leaked due to a bug
in hikari.
links:
- https://github.com/palantir/atlasdb/pull/5963

0 comments on commit 366e1ac

Please sign in to comment.