From a79128d73056da5307ccad1beb62e970a45b5ad3 Mon Sep 17 00:00:00 2001 From: filipe Date: Fri, 10 Jan 2025 18:40:19 -0300 Subject: [PATCH] fix: should wait for ringbuffer thread to finish, otherwise may cause issues of 'ERROR: current transaction is aborted, commands ignored until end of transaction block' This check existed until 2.1.0.21, was replaced by a more complex method in 2.1.0.22 (that already presented issues), and some versions later the replacement was removed. --- .../com/amazon/redshift/jdbc/RedshiftStatementImpl.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/com/amazon/redshift/jdbc/RedshiftStatementImpl.java b/src/main/java/com/amazon/redshift/jdbc/RedshiftStatementImpl.java index a9069fa..3c01e88 100644 --- a/src/main/java/com/amazon/redshift/jdbc/RedshiftStatementImpl.java +++ b/src/main/java/com/amazon/redshift/jdbc/RedshiftStatementImpl.java @@ -741,6 +741,15 @@ public ResultSet getResultSet() throws SQLException { */ public final void close() throws SQLException { + if (connection.getQueryExecutor().isRingBufferThreadRunning() && + (!connection.getAutoCommit() || getMaxRows() == 0)) + { + // Wait for current ring buffer thread to finish, if any. + // Shouldn't call from synchronized method, which can cause dead-lock. + // We don't want to wait for ring buffer to fetch all rows if setMaxRows() is set, + // or if autoCommit is set to true + connection.getQueryExecutor().waitForRingBufferThreadToFinish(false, false, true, null, null); + } if (RedshiftLogger.isEnable()) connection.getLogger().logFunction(true);