Skip to content

Commit

Permalink
fix: ignore errors during Connection.close() (#1877)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
olavloite and gcf-owl-bot[bot] committed May 17, 2022
1 parent 2d2b526 commit 6ab8ed2
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,16 @@ public ApiFuture<Void> 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));
Expand Down

0 comments on commit 6ab8ed2

Please sign in to comment.