diff --git a/src/main/java/org/mariadb/jdbc/MariaDbStatement.java b/src/main/java/org/mariadb/jdbc/MariaDbStatement.java index 890eb820f..38716cbe5 100755 --- a/src/main/java/org/mariadb/jdbc/MariaDbStatement.java +++ b/src/main/java/org/mariadb/jdbc/MariaDbStatement.java @@ -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 { @@ -274,7 +275,6 @@ protected SQLException executeExceptionEpilogue(SQLException sqle) { // eat exception } } - } } @@ -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 { diff --git a/src/main/java/org/mariadb/jdbc/internal/util/pool/Pool.java b/src/main/java/org/mariadb/jdbc/internal/util/pool/Pool.java index 52a009c23..92ad6b317 100644 --- a/src/main/java/org/mariadb/jdbc/internal/util/pool/Pool.java +++ b/src/main/java/org/mariadb/jdbc/internal/util/pool/Pool.java @@ -332,7 +332,13 @@ 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) { @@ -340,7 +346,13 @@ public void connectionClosed(ConnectionEvent event) { // 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.