Skip to content

Commit e0a3e5b

Browse files
authored
fix(spanner): release resources in TransactionManager (#3638)
* fix(spanner): release resources in TransactionManager * fix(spanner): lint fix * chore(spanner): fix comment
1 parent b2ba1f3 commit e0a3e5b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionManagerImpl.java

+10
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ public void commit() {
8080
} catch (SpannerException e2) {
8181
txnState = TransactionState.COMMIT_FAILED;
8282
throw e2;
83+
} finally {
84+
// At this point, if the TransactionState is not ABORTED, then the transaction has reached an
85+
// end state.
86+
// We can safely call close() to release resources.
87+
if (getState() != TransactionState.ABORTED) {
88+
close();
89+
}
8390
}
8491
}
8592

@@ -92,6 +99,9 @@ public void rollback() {
9299
txn.rollback();
93100
} finally {
94101
txnState = TransactionState.ROLLED_BACK;
102+
// At this point, the TransactionState is ROLLED_BACK which is an end state.
103+
// We can safely call close() to release resources.
104+
close();
95105
}
96106
}
97107

0 commit comments

Comments
 (0)