Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(spanner): release resources in TransactionManager #3638

Merged

Conversation

harshachinta
Copy link
Contributor

@harshachinta harshachinta commented Feb 12, 2025

The close() method in TransactionManager was only being called when used within a try-with-resources block, as TransactionManager implements AutoCloseable.

However, in cases where try-with-resources was not used or .close() was not explicitly called, close() was never invoked, leading to resource leaks—such as spans not being closed properly. This is particularly an issue in JDBC, where try-with-resources cannot be used.

This PR ensures that close() is implicitly invoked whenever the transaction reaches an end state, preventing resource leaks.

@harshachinta harshachinta requested review from a team as code owners February 12, 2025 06:37
@product-auto-label product-auto-label bot added size: xs Pull request size is extra small. api: spanner Issues related to the googleapis/java-spanner API. labels Feb 12, 2025
@product-auto-label product-auto-label bot added size: s Pull request size is small. and removed size: xs Pull request size is extra small. labels Feb 12, 2025
@@ -80,6 +80,13 @@ public void commit() {
} catch (SpannerException e2) {
txnState = TransactionState.COMMIT_FAILED;
throw e2;
} finally {
// At this point, if the TransactionState is not ABORTED, then the transaction has reached a
// terminal state.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super-nit: I would recommend using end state instead of terminal state.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, I have used this term from existing code. But end state is more clear in terms of readability.

@harshachinta harshachinta merged commit e0a3e5b into googleapis:main Feb 13, 2025
30 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/java-spanner API. size: s Pull request size is small.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants