From cc7372ca3d8ac2531edec2c6107352d2d95d073c Mon Sep 17 00:00:00 2001 From: anikikong Date: Thu, 1 Jul 2021 07:04:41 +0000 Subject: [PATCH] Handle the exception when cancel query failed. --- .../main/java/org/postgresql/core/QueryExecutorBase.java | 1 + pgjdbc/src/main/java/org/postgresql/jdbc/PgConnection.java | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pgjdbc/src/main/java/org/postgresql/core/QueryExecutorBase.java b/pgjdbc/src/main/java/org/postgresql/core/QueryExecutorBase.java index f4e2ad9..2eaf035 100644 --- a/pgjdbc/src/main/java/org/postgresql/core/QueryExecutorBase.java +++ b/pgjdbc/src/main/java/org/postgresql/core/QueryExecutorBase.java @@ -178,6 +178,7 @@ public abstract class QueryExecutorBase implements QueryExecutor { } catch (IOException e) { // Safe to ignore. LOGGER.trace("Ignoring exception on cancel request:", e); + throw new SQLException("Cancel request on this connection failed"); } finally { if (cancelStream != null) { try { diff --git a/pgjdbc/src/main/java/org/postgresql/jdbc/PgConnection.java b/pgjdbc/src/main/java/org/postgresql/jdbc/PgConnection.java index 419a502..d2b7950 100644 --- a/pgjdbc/src/main/java/org/postgresql/jdbc/PgConnection.java +++ b/pgjdbc/src/main/java/org/postgresql/jdbc/PgConnection.java @@ -1143,7 +1143,11 @@ public class PgConnection implements BaseConnection { @Override public void cancelQuery() throws SQLException { checkClosed(); - queryExecutor.sendQueryCancel(); + try { + queryExecutor.sendQueryCancel(); + } catch (SQLException e) { + queryExecutor.close(); + } } @Override