Skip to content

Commit 8918ff9

Browse files
committed
fix(bigquery-jdbc): rollback active transactions when closing connection
1 parent bb53c59 commit 8918ff9

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryConnection.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,20 @@ private void closeImpl() throws SQLException {
970970
}
971971
this.openStatements.clear();
972972

973+
if (isTransactionStarted()) {
974+
try {
975+
// It looks like there's no need to start a new transaction after a rollback,
976+
// but the commit behavior is preserved since close() may still fail before isClosed is updated.
977+
rollbackImpl();
978+
} catch (SQLException e) {
979+
if (exceptionToThrow == null) {
980+
exceptionToThrow = e;
981+
} else {
982+
exceptionToThrow.addSuppressed(e);
983+
}
984+
}
985+
}
986+
973987
boolean interrupted = Thread.currentThread().isInterrupted();
974988

975989
try {

0 commit comments

Comments
 (0)