Skip to content

Commit 37dd867

Browse files
committed
chore(spanner): fix resource cleanup
1 parent 3eee082 commit 37dd867

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ 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 a terminal state.
85+
// We can safely call close() to release resources.
86+
if (getState() != TransactionState.ABORTED) {
87+
close();
88+
}
8389
}
8490
}
8591

@@ -92,6 +98,9 @@ public void rollback() {
9298
txn.rollback();
9399
} finally {
94100
txnState = TransactionState.ROLLED_BACK;
101+
// At this point, the TransactionState is ROLLED_BACK which is a terminal state.
102+
// We can safely call close() to release resources.
103+
close();
95104
}
96105
}
97106

google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/OpenTelemetryTracingTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
/*
16+
1717
package com.google.cloud.spanner.connection;
1818

1919
import static com.google.cloud.spanner.connection.Repeat.twice;
@@ -679,4 +679,3 @@ private void addUpdateDdlResponse() {
679679
.build());
680680
}
681681
}
682-
*/

0 commit comments

Comments
 (0)