Don't close DataSource with bad connection

- Attempt to recursively obtain a valid connection.
  This could lead to StackOverFlowException if db goes
  down, so that is caught.

Affects issues:
- Possibly fixed #1458
This commit is contained in:
Risto Lahtela 2021-01-22 11:05:57 +02:00
parent 3335765fa2
commit 8423e392bb

View File

@ -127,13 +127,10 @@ public class MySQLDB extends SQLDB {
Connection connection = dataSource.getConnection();
if (!connection.isValid(5)) {
connection.close();
dataSource.close();
try {
setupDataSource();
// get new connection after restarting pool
connection = dataSource.getConnection();
} catch (DBInitException e) {
throw new DBOpException("Failed to restart DataSource after a connection was invalid: " + e.getMessage(), e);
return getConnection();
} catch (StackOverflowError databaseHasGoneDown) {
throw new DBOpException("Valid connection could not be fetched (Is MySQL down?) - attempted until StackOverflowError occurred.", databaseHasGoneDown);
}
}
if (connection.getAutoCommit()) connection.setAutoCommit(false);