diff --git a/bukkit/pom.xml b/bukkit/pom.xml index 0f2986bf8..f36faa58d 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -101,13 +101,6 @@ 0.0.1-SNAPSHOT provided - - - com.zaxxer - HikariCP - 2.5.1 - provided - org.projectlombok diff --git a/common/pom.xml b/common/pom.xml index aadf8e4dd..379795742 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -50,7 +50,7 @@ com.zaxxer HikariCP - 2.5.1 + 2.6.1 provided diff --git a/common/src/main/java/me/lucko/luckperms/common/dependencies/Dependency.java b/common/src/main/java/me/lucko/luckperms/common/dependencies/Dependency.java index f046fbe10..1004f52b9 100644 --- a/common/src/main/java/me/lucko/luckperms/common/dependencies/Dependency.java +++ b/common/src/main/java/me/lucko/luckperms/common/dependencies/Dependency.java @@ -33,7 +33,7 @@ public enum Dependency { POSTGRESQL_DRIVER("https://repo1.maven.org/maven2/org/postgresql/postgresql/9.4.1212/postgresql-9.4.1212.jar", "9.4.1212", "org.postgresql.ds.PGSimpleDataSource"), H2_DRIVER("https://repo1.maven.org/maven2/com/h2database/h2/1.4.193/h2-1.4.193.jar", "1.4.193", "org.h2.Driver"), SQLITE_DRIVER("https://repo1.maven.org/maven2/org/xerial/sqlite-jdbc/3.15.1/sqlite-jdbc-3.15.1.jar", "3.15.1", "org.sqlite.JDBC"), - HIKARI("https://repo1.maven.org/maven2/com/zaxxer/HikariCP/2.5.1/HikariCP-2.5.1.jar", "2.5.1", "com.zaxxer.hikari.HikariDataSource"), + HIKARI("https://repo1.maven.org/maven2/com/zaxxer/HikariCP/2.6.1/HikariCP-2.6.1.jar", "2.6.1", "com.zaxxer.hikari.HikariConfig"), SLF4J_SIMPLE("https://repo1.maven.org/maven2/org/slf4j/slf4j-simple/1.7.9/slf4j-simple-1.7.9.jar", "1.7.9", "org.slf4j.impl.SimpleLoggerFactory"), SLF4J_API("https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.9/slf4j-api-1.7.9.jar", "1.7.9", "org.slf4j.helpers.BasicMarkerFactory"), MONGODB_DRIVER("https://repo1.maven.org/maven2/org/mongodb/mongo-java-driver/3.4.1/mongo-java-driver-3.4.1.jar", "3.4.1", "com.mongodb.Mongo"), diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/FlatfileProvider.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/FlatfileProvider.java index b0c60f0a2..864571823 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/FlatfileProvider.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/FlatfileProvider.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.common.storage.backing.sqlprovider; import java.io.File; +import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.concurrent.locks.ReentrantLock; @@ -57,18 +58,25 @@ abstract class FlatfileProvider extends SQLProvider { public WrappedConnection getConnection() throws SQLException { lock.lock(); try { - if (connection == null || connection.isClosed()) { + if (this.connection == null || this.connection.isClosed()) { try { Class.forName(getDriverClass()); } catch (ClassNotFoundException ignored) {} - connection = new WrappedConnection(DriverManager.getConnection(getDriverId() + ":" + file.getAbsolutePath()), false); + Connection connection = DriverManager.getConnection(getDriverId() + ":" + file.getAbsolutePath()); + if (connection != null) { + this.connection = new WrappedConnection(connection, false); + } } } finally { lock.unlock(); } - return connection; + if (this.connection == null) { + throw new SQLException("Connection is null"); + } + + return this.connection; } } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/MySQLProvider.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/MySQLProvider.java index de555ad00..091328f5c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/MySQLProvider.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/MySQLProvider.java @@ -27,6 +27,7 @@ import com.zaxxer.hikari.HikariDataSource; import me.lucko.luckperms.common.storage.DatastoreConfiguration; +import java.sql.Connection; import java.sql.SQLException; import java.util.concurrent.TimeUnit; @@ -62,21 +63,26 @@ public class MySQLProvider extends SQLProvider { config.addDataSourceProperty("databaseName", database); config.addDataSourceProperty("user", username); config.addDataSourceProperty("password", password); - config.addDataSourceProperty("cachePrepStmts", true); - config.addDataSourceProperty("prepStmtCacheSize", 250); - config.addDataSourceProperty("prepStmtCacheSqlLimit", 2048); - config.addDataSourceProperty("useServerPrepStmts", true); - config.addDataSourceProperty("cacheCallableStmts", true); - config.addDataSourceProperty("alwaysSendSetIsolation", false); - config.addDataSourceProperty("cacheServerConfiguration", true); - config.addDataSourceProperty("elideSetAutoCommits", true); - config.addDataSourceProperty("useLocalSessionState", true); + config.addDataSourceProperty("cachePrepStmts", "true"); + config.addDataSourceProperty("prepStmtCacheSize", "250"); + config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); + config.addDataSourceProperty("useServerPrepStmts", "true"); + config.addDataSourceProperty("cacheCallableStmts", "true"); + config.addDataSourceProperty("alwaysSendSetIsolation", "false"); + config.addDataSourceProperty("cacheServerConfiguration", "true"); + config.addDataSourceProperty("elideSetAutoCommits", "true"); + config.addDataSourceProperty("useLocalSessionState", "true"); config.addDataSourceProperty("characterEncoding", "utf8"); config.addDataSourceProperty("useUnicode", "true"); - config.setConnectionTimeout(TimeUnit.SECONDS.toMillis(10)); // 10000 - config.setLeakDetectionThreshold(TimeUnit.SECONDS.toMillis(5)); // 5000 - config.setValidationTimeout(TimeUnit.SECONDS.toMillis(3)); // 3000 - config.setInitializationFailFast(true); + + // We will wait for 15 seconds to get a connection from the pool. + // Default is 30, but it shouldn't be taking that long. + config.setConnectionTimeout(TimeUnit.SECONDS.toMillis(15)); // 15000 + + // If a connection is not returned within 10 seconds, it's probably safe to assume it's been leaked. + config.setLeakDetectionThreshold(TimeUnit.SECONDS.toMillis(10)); // 10000 + + // The drivers are really old in some of the older Spigot binaries, so Connection#isValid doesn't work. config.setConnectionTestQuery("/* LuckPerms ping */ SELECT 1"); hikari = new HikariDataSource(config); @@ -91,6 +97,10 @@ public class MySQLProvider extends SQLProvider { @Override public WrappedConnection getConnection() throws SQLException { - return new WrappedConnection(hikari.getConnection(), true); + Connection connection = hikari.getConnection(); + if (connection == null) { + throw new SQLException("Connection is null"); + } + return new WrappedConnection(connection, true); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/PostgreSQLProvider.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/PostgreSQLProvider.java index feed77c74..2b4ca269b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/PostgreSQLProvider.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/PostgreSQLProvider.java @@ -27,6 +27,7 @@ import com.zaxxer.hikari.HikariDataSource; import me.lucko.luckperms.common.storage.DatastoreConfiguration; +import java.sql.Connection; import java.sql.SQLException; import java.util.concurrent.TimeUnit; @@ -62,10 +63,15 @@ public class PostgreSQLProvider extends SQLProvider { config.addDataSourceProperty("databaseName", database); config.addDataSourceProperty("user", username); config.addDataSourceProperty("password", password); - config.setConnectionTimeout(TimeUnit.SECONDS.toMillis(10)); // 10000 - config.setLeakDetectionThreshold(TimeUnit.SECONDS.toMillis(5)); // 5000 - config.setValidationTimeout(TimeUnit.SECONDS.toMillis(3)); // 3000 - config.setInitializationFailFast(true); + + // We will wait for 15 seconds to get a connection from the pool. + // Default is 30, but it shouldn't be taking that long. + config.setConnectionTimeout(TimeUnit.SECONDS.toMillis(15)); // 15000 + + // If a connection is not returned within 10 seconds, it's probably safe to assume it's been leaked. + config.setLeakDetectionThreshold(TimeUnit.SECONDS.toMillis(10)); // 10000 + + // Just in-case the driver isn't JDBC4+ config.setConnectionTestQuery("/* LuckPerms ping */ SELECT 1"); hikari = new HikariDataSource(config); @@ -80,6 +86,10 @@ public class PostgreSQLProvider extends SQLProvider { @Override public WrappedConnection getConnection() throws SQLException { - return new WrappedConnection(hikari.getConnection(), true); + Connection connection = hikari.getConnection(); + if (connection == null) { + throw new SQLException("Connection is null"); + } + return new WrappedConnection(connection, true); } }