Skip to content

Commit 6ab8ed2

Browse files
fix: ignore errors during Connection.close() (#1877)
* 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 <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 2d2b526 commit 6ab8ed2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionImpl.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,16 @@ public ApiFuture<Void> closeAsync() {
298298
abortBatch();
299299
}
300300
if (isTransactionStarted()) {
301-
futures.add(rollbackAsync());
301+
try {
302+
futures.add(rollbackAsync());
303+
} catch (Exception exception) {
304+
// ignore and continue to close the connection.
305+
}
302306
}
303307
// Try to wait for the current statement to finish (if any) before we actually close the
304308
// connection.
305309
this.closed = true;
306-
// Add a no-op statement to the execute. Once this has been executed, we know that all
310+
// Add a no-op statement to the executor. Once this has been executed, we know that all
307311
// preceding statements have also been executed, as the executor is single-threaded and
308312
// executes all statements in order of submitting.
309313
futures.add(statementExecutor.submit(() -> null));

0 commit comments

Comments
 (0)