Skip to content

Commit

Permalink
[CONJ-884] ensure pool state when connection error occurs during conn…
Browse files Browse the repository at this point in the history
…ection reset
  • Loading branch information
rusher committed Jul 27, 2021
1 parent 1056012 commit 4ea0eab
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
24 changes: 12 additions & 12 deletions src/main/java/org/mariadb/jdbc/MariaDbStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,21 +248,22 @@ protected SQLException executeExceptionEpilogue(SQLException sqle) {
try {
if (sqle.getErrorCode() == 1148 && !options.allowLocalInfile) {
return exceptionFactory
.raiseStatementError(connection, this)
.create(
"Usage of LOCAL INFILE is disabled. To use it enable it via the connection property allowLocalInfile=true",
"42000",
1148,
sqle);
.raiseStatementError(connection, this)
.create(
"Usage of LOCAL INFILE is disabled. To use it enable it via the connection property allowLocalInfile=true",
"42000",
1148,
sqle);
}

if (isTimedout) {
return exceptionFactory
.raiseStatementError(connection, this)
.create("Query timed out", "70100", 1317, sqle);
.raiseStatementError(connection, this)
.create("Query timed out", "70100", 1317, sqle);
}

SQLException sqlException = exceptionFactory.raiseStatementError(connection, this).create(sqle);
SQLException sqlException =
exceptionFactory.raiseStatementError(connection, this).create(sqle);
logger.error("error executing query", sqlException);
return sqlException;
} finally {
Expand All @@ -274,7 +275,6 @@ protected SQLException executeExceptionEpilogue(SQLException sqle) {
// eat exception
}
}

}
}

Expand All @@ -295,8 +295,8 @@ private SQLException handleFailoverAndTimeout(SQLException sqle) {
try {
if (isTimedout) {
return exceptionFactory
.raiseStatementError(connection, this)
.create("Query timed out", "70100", 1317, sqle);
.raiseStatementError(connection, this)
.create("Query timed out", "70100", 1317, sqle);
}
return sqle;
} finally {
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/org/mariadb/jdbc/internal/util/pool/Pool.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,27 @@ public void connectionClosed(ConnectionEvent event) {
if (poolState.get() == POOL_STATE_OK) {
try {
if (!idleConnections.contains(item)) {
// remove pool connection to avoid throwing connectionErrorOccurred
item.getConnection().pooledConnection = null;

item.getConnection().reset();

// set pool connection back
item.getConnection().pooledConnection = item;
idleConnections.addFirst(item);
}
} catch (SQLException sqle) {

// sql exception during reset, removing connection from pool
totalConnection.decrementAndGet();
silentCloseConnection(item);
logger.debug("connection removed from pool {} due to error during reset", poolTag);
logger.debug(
"connection {} removed from pool {} due to error during reset (total:{}, active:{}, pending:{})",
item.getConnection().getServerThreadId(),
poolTag,
totalConnection.get(),
getActiveConnections(),
pendingRequestNumber.get());
}
} else {
// pool is closed, should then not be render to pool, but closed.
Expand Down

0 comments on commit 4ea0eab

Please sign in to comment.