Hello.
Someone reported this exception to me, and I’m quite unable to figure it out.
It says that the data source my MySQL was using has been closed and I don’t know what could do such a thing.
...
Caused by:
java.sql.SQLException: HikariDataSource HikariDataSource (HikariPool-2) has been closed.
com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:81)
com.djrapitops.plan.system.database.databases.sql.MySQLDB.getConnection(MySQLDB.java:62)
com.djrapitops.plan.system.database.databases.sql.tables.Table.getConnection(Table.java:60)
com.djrapitops.plan.system.database.databases.sql.tables.Table.query(Table.java:203)
com.djrapitops.plan.system.database.databases.sql.tables.ServerTable.getServerID(ServerTable.java:120)
com.djrapitops.plan.system.database.databases.sql.operation.SQLCheckOps.isServerInDatabase(SQLCheckOps.java:52)
com.djrapitops.plan.system.info.connection.ConnectionIn.checkAuthentication(ConnectionIn.java:40)
com.djrapitops.plan.system.info.connection.ConnectionIn.(ConnectionIn.java:33)
com.djrapitops.plan.system.info.connection.InfoRequestPageHandler.getResponse(InfoRequestPageHandler.java:47)
com.djrapitops.plan.system.webserver.ResponseHandler.getResponse(ResponseHandler.java:114)
com.djrapitops.plan.system.webserver.ResponseHandler.getResponse(ResponseHandler.java:62)
com.djrapitops.plan.system.webserver.RequestHandler.handle(RequestHandler.java:45)
com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79)
sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:83)
com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:82)
sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:675)
com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79)
sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:647)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)
In my plugin the generic MySQL is closed in the following way:
@Override
public void close() {
try {
if (dataSource != null && dataSource instanceof BasicDataSource) {
((BasicDataSource) dataSource).close();
}
} catch (SQLException e) {
Log.toLog(this.getClass(), e);
}
super.close();
}
AFAIK HikariDataSource isn’t a apache.dhcp2.BasicDataSource so it should not close the DataSource when shutting down the plugin.
What could be causing the closing?
Additional information:
the DataSource is initialized like this when database is opened
@Override
public void setupDataSource() throws DBInitException {
Optional<SqlService> sqlServiceProvider = Sponge.getServiceManager().provide(SqlService.class);
if (!sqlServiceProvider.isPresent()) {
return;
}
String host = Settings.DB_HOST.toString();
String port = Integer.toString(Settings.DB_PORT.getNumber());
String database = Settings.DB_DATABASE.toString();
String launchOptions = Settings.DB_LAUNCH_OPTIONS.toString();
if (launchOptions.isEmpty() || !launchOptions.startsWith("?") || launchOptions.endsWith("&")) {
Log.error("Launch Options were faulty, using default (?rewriteBatchedStatements=true&useSSL=false)");
launchOptions = "?rewriteBatchedStatements=true&useSSL=false";
}
String url = host + ":" + port + "/" + database + launchOptions;
String username = Settings.DB_USER.toString();
String password = Settings.DB_PASS.toString();
try {
this.dataSource = sqlServiceProvider.get().getDataSource(
"jdbc:mysql://" + username + ":" + password + "@" + url
);
} catch (SQLException e) {
throw new DBInitException(e);
}
}