From 6ab8ed236b1393e67a4edc5d430d9535dffbadb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Olav=20L=C3=B8ite?= Date: Tue, 17 May 2022 09:01:08 +0200 Subject: [PATCH] fix: ignore errors during Connection.close() (#1877) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: ignore errors during Connection.close() A connection will automatically rollback any active transactions when the connection is closed. If the rollback would throw an exception, the close would fail and the connection would still be marked as open. This fix adds a simple ignore error handler when rolling back a transaction when the connection is closed. * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot --- .../google/cloud/spanner/connection/ConnectionImpl.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionImpl.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionImpl.java index 8f6d0aaae1a..c6251e64db5 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionImpl.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionImpl.java @@ -298,12 +298,16 @@ public ApiFuture closeAsync() { abortBatch(); } if (isTransactionStarted()) { - futures.add(rollbackAsync()); + try { + futures.add(rollbackAsync()); + } catch (Exception exception) { + // ignore and continue to close the connection. + } } // Try to wait for the current statement to finish (if any) before we actually close the // connection. this.closed = true; - // Add a no-op statement to the execute. Once this has been executed, we know that all + // Add a no-op statement to the executor. Once this has been executed, we know that all // preceding statements have also been executed, as the executor is single-threaded and // executes all statements in order of submitting. futures.add(statementExecutor.submit(() -> null));